How to implement correctly a nested loop?

10 Ansichten (letzte 30 Tage)
Paul Jimenez
Paul Jimenez am 26 Nov. 2020
Kommentiert: Stephan am 27 Nov. 2020
Hi I'm developing a code using the most recent version of Matlab but I having trouble to figured out how to create a correct nested loop.
My code is actually quite long and for academic reasons I can not show it here, but let's say that I'm trying to nest 3 different loops: one loop to create multiple arrays with vectors inside each array, then another loop to create a set of initial conditions depending on those arrays from the previous loop and finally one loop to iterate for a fixed number of times a system of ODES, using those initial conditions. For all the loops I'm using the for coomand of course.
I tried before with 2 loops and it worked correctly but when I try to add the third loop I got several errors most of them about wrong variables and not enough input arguments, so I'm assuming that the order in which the loops are nested is not correct but I would like to hear any suggestion or if is possible an example of how you can nest multiple loops in a proper manner. I know that without a code would be very hard to find a good solution but it would be nice if someone can share any problems similar to this and how it was fixed.
Thanks
  3 Kommentare
Paul Jimenez
Paul Jimenez am 27 Nov. 2020
Bearbeitet: Paul Jimenez am 27 Nov. 2020
The error that I usually get is this: Unrecognized function or variable.
Stephan
Stephan am 27 Nov. 2020
This error means that you use or call a variable or function which is not defined. You could use the little arrow at the RUN button ans set "Pause in errors" active. This will help debug.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by