필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How do i do a for loop within a for loop with a variable changing n=1:42.

조회 수: 4 (최근 30일)
Andrew Wiebe
Andrew Wiebe 2015년 9월 23일
마감: MATLAB Answer Bot 2021년 8월 20일
If i wanted to create a for loop where n=1:42, but there is another variable, l whose dimension is dependant on the variable n. how would i notate the change for l. for instance, if for n=2:6,9 l=1:16 but for n=42, l=1:53, how could i construct the for loops to give me outputs without the error "indices exceed matrix dimensions" Thanks

답변 (1개)

James Tursa
James Tursa 2015년 9월 23일
Why can't you use simple if-tests on the value of n to set the value of I?
  댓글 수: 1
Andrew Wiebe
Andrew Wiebe 2015년 9월 23일
편집: Stephen23 2015년 9월 23일
would i do this
for n=1:42;
if n=[2:6 9] l=1:16;
equation equation;
end
if n=42 l=1:53;
equation equation;
end
end
or would i do
for n=1:42;
if n=[2:6 9] l=1:16;
if n=42 l=1:53;
equation equation;
end
end
thanks a lot!

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by