For Loop No Idea!
Show older comments
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 Comments
Albert Yam
on 30 Jul 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
on 30 Jul 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
on 30 Jul 2012
The loop as written is overwriting x1 and y1 on each iteration of the two loops.
What is your desired output?
Adam Parry
on 30 Jul 2012
Edited: Adam Parry
on 30 Jul 2012
Adam Parry
on 30 Jul 2012
Walter Roberson
on 30 Jul 2012
return will likely not help.
"break" might possibly help, perhaps.
Answers (2)
Adam Parry
on 31 Jul 2012
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!