repeat n times vector with name index

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일

0 개 추천

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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2022년 12월 1일

댓글:

2022년 12월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by