I would like to program a loop over a number of strings of different length. My problem is that I don't get my various strings stored in one element. I've tried the following:
string=['string1';'long开发者_高级运维erstring2']
%# Store
string = {'string1','longerstring2'};
%# Access
disp(string{1});
Output:
string1
You will need to store the strings in a cell array. The cellstr function may be useful to you for generating the cell array from a list of strings of equal length (padded with spaces), or you could just create the cell array manually.
The other solutions if you're happy with a cell array. Alternatively, you can do
char('string1','longerstring2')
which will pad with spaces, so is equivalent to (in this case):
['string1 ';'longerstring2']
精彩评论