Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

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

4 Ansichten (letzte 30 Tage)
Andrew Wiebe
Andrew Wiebe am 23 Sep. 2015
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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

Antworten (1)

James Tursa
James Tursa am 23 Sep. 2015
Why can't you use simple if-tests on the value of n to set the value of I?
  1 Kommentar
Andrew Wiebe
Andrew Wiebe am 23 Sep. 2015
Bearbeitet: Stephen23 am 23 Sep. 2015
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!

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by