我想创建一个循环,该循环在每次迭代后创建一个不同的变量名 [英] I would like to create a loop that creates a different variable name after each iteration

查看:62
本文介绍了我想创建一个循环,该循环在每次迭代后创建一个不同的变量名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以e_1e_2e_3的形式创建一组不同的变量.变量的数量取决于k的值,如下所示.

I would like to create a set of distinct variables in the form of e_1, e_2, e_3... The number of variables would depend on the value of k as shown below.

for i = 1:k

  "create variable" = e_"i";

end

然后我要调用这些变量;因此,我需要另一个循环,该循环将能够为之前创建的每个变量分配正确的值,或者从变量中提取一些东西.

I will then want to call these variables; hence, I would need another loop that would be able to assign the correct value to each variable created before, or pull something out of the variable.

推荐答案

一种选择是做这样的事情:

One option would be to do something like this:

kk = 10;
for ii=1:kk
  eval(['e_' num2str(ii) '=[];'])
end

这篇关于我想创建一个循环,该循环在每次迭代后创建一个不同的变量名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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