追加字符串数组Matlab的 [英] Appending string to Matlab array

查看:883
本文介绍了追加字符串数组Matlab的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将字符串追加到一个Matlab阵列列明智?

下面是什么,我试图做一个小code片断:

  FOR_LOOP
  文件名=字符串;
  命名= [名;文件名]
结束


解决方案

您需要使用电池阵列。如果迭代次数是事先知道的,我建议你preallocate:

  N = 10;
名称=小区(1,N);
对于i = 1:N
    名称{I} =字符串;
结束

否则你可以这样做:

 名称= {};
对于i = 1:10
    名{结束+ 1} =字符串;
结束

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

otherwise you can do something like:

names = {};
for i=1:10
    names{end+1} = 'string';
end

这篇关于追加字符串数组Matlab的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆