Create matrix with strings

19 ビュー (過去 30 日間)
Wim
Wim 2014 年 5 月 13 日
回答済み: David Sanchez 2014 年 5 月 13 日
Hello,
I want to create a matrix filled with strings of dimension amount x 1 Then I run a for-loop and for each i I want to fill in the i-row with a string.
Eventually I want Matlab to give as answer:
>>matrix =
String1
String2
...
How can I achieve this? Thanks!

回答 (1 件)

David Sanchez
David Sanchez 2014 年 5 月 13 日
If the strings will have different length, you can not do it. Instead use a cell array:
amount = 3; % or whatever you want
my_cell = cell(amount,1); % empty 3x1 cell array
for k=1:amount
tmp = sprintf('String%g',k);
my_cell{k} = tmp;
end
my_cell =
'String1'
'String2'
'String3'

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by