For Loop No Idea!

조회 수: 3(최근 30일)
Adam Parry
Adam Parry 2012년 7월 30일
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
Walter Roberson
Walter Roberson 2012년 7월 30일
return will likely not help.
"break" might possibly help, perhaps.

댓글을 달려면 로그인하십시오.

답변(2개)

Walter Roberson
Walter Roberson 2012년 7월 30일

Adam Parry
Adam Parry 2012년 7월 31일
Hello people kind enough to help.
I have got myself stuck again.
Apparently Matlab does not like this either
for i = 1:VgStep
for start = 1:VgStep:endPoint-VgStep
for step = VgStep:VgStep:endPoint
XX(i) = x(start:step);
YY(i) = y(start:step);
end
end
end
pops up with this error
In an assignment A(I) = B, the number of elements in B and I must be
the same.
  댓글 수: 2
Adam Parry
Adam Parry 2012년 7월 31일
sorry just realised I was using the wrong brackets, should have been
for i = 1:VgStep
for start = 1:VgStep:endPoint-VgStep
for step = VgStep:VgStep:endPoint
XX{i} = x(start:step);
YY{i} = y(start:step);
end
end
end

댓글을 달려면 로그인하십시오.

범주

Find more on Loops and Conditional Statements 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!

Translated by