For Loop No Idea!
Afficher commentaires plus anciens
So I'm not used to how you write programming code in Matlab, or really any language to be honest, so could someone tell me how to make this for loop work
for start = 1:VgStep:endPoint-VgStep
for step = VgStep:VgStep:endPoint
x1 = x(start:step);
y1 = y(start:step);
end
end
I think you can probably get the general idea of what I would like it to do..
6 commentaires
Albert Yam
le 30 Juil 2012
The loop you are writing is looking for the vector 'x', elements from 'start' to 'step', and putting that into x1 (and same for y1). Are you sure that is what you want to do?
Ryan
le 30 Juil 2012
All I got out of that is that you are trying to save some variables in a loop:
Try explaining your problem or goals instead of placing code that you don't understand enough to even ask a question about it.
What information are you trying to get from x and y using these start and step terms? Currently through the loop you are saving over x1 and y1 each time with the values in vectors x and y with the values of those vectors between your current values of start and step (the start:step) - did you want that?
Walter Roberson
le 30 Juil 2012
The loop as written is overwriting x1 and y1 on each iteration of the two loops.
What is your desired output?
Adam Parry
le 30 Juil 2012
Modifié(e) : Adam Parry
le 30 Juil 2012
Adam Parry
le 30 Juil 2012
Walter Roberson
le 30 Juil 2012
return will likely not help.
"break" might possibly help, perhaps.
Réponses (2)
Adam Parry
le 31 Juil 2012
2 commentaires
Adam Parry
le 31 Juil 2012
Modifié(e) : Adam Parry
le 31 Juil 2012
Adam Parry
le 31 Juil 2012
Catégories
En savoir plus sur Structures dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!