如何在MATLAB中的循环中重命名变量? [英] How to rename a variable in a loop in MATLAB?

查看:688
本文介绍了如何在MATLAB中的循环中重命名变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉在MATLAB的每次循环迭代中是否存在重命名变量的方法?

Can somebody please tell if there exists a way to rename a variable in each iteration of a loop in MATLAB?

实际上,我想将变量保存到循环中,并使用包含循环索引的其他名称.谢谢.

Actually, I want to save a variable in a loop with a different name incorporating the index of the loop. Thanks.

推荐答案

根据您的评论,我建议使用

Based on your comment, I suggest using a cell array. This allows any type of result to be stored by index. For example:

foo=cell(bar,1);
for ii=1:bar
    foo{ii}=quux;
end

然后您可以保存foo保留所有中间结果.尽管循环索引没有按需要包含在变量名中,但它提供了相同的功能.

You can then save foo to retain all your intermediate results. Though the loop index is not baked into the variable name as you want, this offers identical functionality.

这篇关于如何在MATLAB中的循环中重命名变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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