Create an array of strings

后端 未结 7 1917
走了就别回头了
走了就别回头了 2020-12-15 03:11

Is it possibe to create an array of strings in MATLAB within a for loop?

For example,

for i=1:10
Names(i)=\'Sample Text\';
end

I do

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-15 03:40

    As already mentioned by Amro, the most concise way to do this is using cell arrays. However, Budo touched on the new string class introduced in version R2016b of MATLAB. Using this new object, you can very easily create an array of strings in a loop as follows:

    for i = 1:10
      Names(i) = string('Sample Text');
    end
    

提交回复
热议问题