repeat n times vector with name index

2 次查看(过去 30 天)
i hope someone can help me
i need to repeat these 4 lines of code n times with the variable {i} changing from 1 until n
E{i}=trapz(days,D{i});
e{i}=D{i}(1,1);
ee{i}=D{i}(5,1);
Etotal{i}=E{i}A+570*e{i}+2330*ee{i};
D{i} is a series of data vectors imported ( D1 D2 .... Dn) (the index "i" in this case refers only to the name of the vector)
  1 个评论
Stephen23
Stephen23 2022-12-1
"D{i} is a series of data vectors imported ( D1 D2 .... Dn) (the index "i" in this case refers only to the name of the vector)"
Best solution: fix the data importing, so that you are not forcing meta-data into variable names. Use indexing.

请先登录,再进行评论。

回答(1 个)

Fangjun Jiang
Fangjun Jiang 2022-12-1
for i=1:n
E{i}=trapz(days,D{i});
e{i}=D{i}(1,1);
ee{i}=D{i}(5,1);
Etotal{i}=E{i}A+570*e{i}+2330*ee{i};
end
  1 个评论
charles aouad
charles aouad 2022-12-1
thank you @Fangjun Jiang i tried this but i get the follwoing error in the second line:
Brace indexing is not supported for variables of this type.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by