For Loop No Idea!

1 回表示 (過去 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 件のコメント
Adam Parry
Adam Parry 2012 年 7 月 30 日
could i use some kind of return command?
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 日
編集済み: Adam Parry 2012 年 7 月 31 日
x y Vg
0 8908 0
-1 908 0
-2 7897 0
0 8908 -1
-1 8908 -1
-2 789789 -1
0 8908 -2
-1 784732 -2
-2 89034 -2
That is more like what the data looks like sorry
and this is the rest of the code
x = A.data(:,1);
y = abs(A.data(:,2));
Vg = A.data(:,3);
minx = min(x);
MaxX = (-minx)+1;
VgMin = min(Vg);
VgStep = (-VgMin/1)+1;
endPoint = (VgStep*MaxX);
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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by