I want to concatenate (padding with spaces) the strings in a cell array {'a', 'b'}
to give a single string 'a b'
. How can I do this in MATLAB?
相关问题
- Extract matrix elements using a vector of column i
- how to split a list into a given number of sub-lis
- Generate string from integer with arbitrary base i
- Converting a string array to a byte array
- How do I merge consecutive numbers in a sorted lis
相关文章
- JSP String formatting Truncate
- Selecting only the first few characters in a strin
- Python: print in two columns
- How do I append metadata to an image in Matlab?
- extending c++ string member functions
- Google app engine datastore string encoding proble
- How can I write-protect the Matlab language?
- How to measure complexity of a string?
Both
join
andstrjoin
are introduced in R2013a. However, the mathworks site aboutstrjoin
reads:Personally I like Alex' solution as well, as older versions of Matlab are abundant in research groups around the world.
You can cheat a bit, by using the cell array as a set of argument to the sprintf function, then cleaning up the extra spaces with strtrim:
Dirty, but I like it...
Small improvement (?) on the answer by Alex
You can accomplish this using the function STRCAT to append blanks to all but the last cell of your cell array and then concatenate all the strings together:
matlab have a function to do this,
ref:
strjoin
http://www.mathworks.com/help/matlab/ref/strjoin.html
strjoin
Join strings in cell array into single string
Syntax
Ex:
Join List of Words with Whitespace
Join individual strings in a cell array of strings, C, with a single space.