필터 지우기
필터 지우기

Can anyone tell me the syntax to create a new variable in each iteration of for loop

조회 수: 1 (최근 30일)
My aim is to create u_Q1_H1(n) for H=1, u_Q1_H2(n) for H=2...and so on...
for H=1:4
if ((u_Q1(n)*v_Q1(n))> (H*s_U*s_V))
u_Q1_H'num2str(H)'(n)= u_Q1(n);
v_Q1_H'num2str(H)'(n)= v_Q1(n);
end
end

채택된 답변

Titus Edelhofer
Titus Edelhofer 2015년 9월 16일
Hi,
I strongly recommend to use cell arrays instead of creating variables that way:
u_Q1_H = cell(1, 4);
v_Q1_H = cell(1, 4);
for H=1:4
if ((u_Q1(n)*v_Q1(n))> (H*s_U*s_V))
u_Q1_H{H}(n)= u_Q1(n);
v_Q1_H{H}(n)= v_Q1(n);
end
end
Assuming there is some loop on n, you should initialize u_Q1_H{H} with zeros.
Titus

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by