将字符串附加到 Matlab 数组 [英] Appending string to Matlab array
本文介绍了将字符串附加到 Matlab 数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将字符串附加到 Matlab 数组列明智?
How do I append a string to a Matlab array column wise?
这是我正在尝试做的一个小代码片段:
Here is a small code snippet of what I am trying to do:
for_loop
filename = 'string';
name=[name; filename]
end
推荐答案
您需要使用元胞数组.如果事先知道迭代次数,我建议你预先分配:
You need to use cell arrays. If the number of iterations are known beforehand, I suggest you preallocate:
N = 10;
names = cell(1,N);
for i=1:N
names{i} = 'string';
end
否则你可以这样做:
names = {};
for i=1:10
names{end+1} = 'string';
end
这篇关于将字符串附加到 Matlab 数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文