Create an array of strings

后端 未结 7 1884
走了就别回头了
走了就别回头了 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:24

    Another solution to this old question is the new container string array, introduced in Matlab 2016b. From what I read in the official Matlab docs, this container resembles a cell-array and most of the array-related functions should work out of the box. For your case, new solution would be:

    a=repmat('Some text', 10, 1);
    

    This solution resembles a Rich C's solution applied to string array.

提交回复
热议问题