For Loop No Idea!
显示 更早的评论
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 个评论
Albert Yam
2012-7-30
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
2012-7-30
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
2012-7-30
The loop as written is overwriting x1 and y1 on each iteration of the two loops.
What is your desired output?
Adam Parry
2012-7-30
编辑:Adam Parry
2012-7-30
Adam Parry
2012-7-30
Walter Roberson
2012-7-30
return will likely not help.
"break" might possibly help, perhaps.
回答(2 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!