首页 > 解决方案 > 如何在 Maltab 中更改变量的名称(添加索引)?

问题描述

我有以下脚本:

a=[1,2,3]
for i=1:length(a)
  e=0;
  e1=0;
  e2=0;
..... 

end

在脚本中,主循环(第一个)是 for i=1:length(a). e, e1,e2应该为每个重写为a(i)

% I count the error
a=1:  e=0;
      e1=0;
      e2=0;
a=2:  e=0;
      e1=0;
      e2=0;
a=3:  e=0;
      e1=0;
      e2=0;

根据我的第一个脚本,Matlab为每个e, e1,e2 , but I neede ,e1重写。,e2a(i)

问题:是否可以更改每个变量的名称a(i)

% to change like this?
a=1:  e_a_1=0;
      e1_a_1=0;
      e2_a_1=0;
a=2:  e_a_2=0;
      e1_a_2=0;
      e2_a_2=0;
a=3:  e_a_2=0;
      e1_a_2=0;
      e2_a_2=0;

标签: matlab

解决方案


推荐阅读