How to manipulate the index of the for loop

3 ビュー (過去 30 日間)
Mallikarjuna
Mallikarjuna 2013 年 12 月 23 日
編集済み: Jan 2013 年 12 月 23 日
Hi,
I have to change the index of the for loop inside the loop only. Something like this,
for i1 = 1:10
if i1 =4
i1 = 6;
end
end
But I am not able to do this. Can some one help me in doing this.
Thanks,
Mallikarjun
  1 件のコメント
Jan
Jan 2013 年 12 月 23 日
Of course "you are able to do this". You can write it down and it is valid Matlab code, such that it will run (except for the == operator in the if condition). But I can guess, that you want to do something else. Then please explain explicitly, what you want and what you get. Relying on the power to guess problems and intentions is a bad idea in a forum.

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

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 12 月 23 日
編集済み: Azzi Abdelmalek 2013 年 12 月 23 日
for i1 = 1:10
if i1==4
i1 = 6;
end
end
when i1==4 you set i1 to 6 ; the next iteration i1 will be equal to 5
%or
v=1:10;
v(v==4)=6;
for i1 = v
%do
end

その他の回答 (1 件)

Jan
Jan 2013 年 12 月 23 日
編集済み: Jan 2013 年 12 月 23 日
A WHILE loop would work:
i1 = 1;
while i1 <= 10
if i1 == 4
i1 = 6;
end
i1 = i1 + 1;
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