how to come out of loop after getting a positive elemnt

1 回表示 (過去 30 日間)
Rutika Titre
Rutika Titre 2015 年 12 月 2 日
コメント済み: Rutika Titre 2015 年 12 月 2 日
hello,
if my row vector x=[-1 -1 -1 -1 -1 3 -1 -1], I am sorting this row vector by giving s=sort(x); so i get the s=[-1 -1 -1 -1 -1 -1 -1 3]; using loop
x=[-1 -1 -1 -1 -1 3 -1 -1];
s=sort(x);
if ii=1:length(s)
if s(ii)<-1
continue;
here i want that after sorting I get 3 as the last element which is only the positive element so break the loop and go to next row.
I have a matrix of size 5X8 I just want the condition for it.
Thank-you!

採用された回答

Walter Roberson
Walter Roberson 2015 年 12 月 2 日
for ii = 1 : upper limit
if the condition is met
continue
end
do something
end
The "do something" will not be done if the condition is met.
You should also be considering using
for ii = 1 : upper limit
if the condition is not met
do something
end
end
  1 件のコメント
Rutika Titre
Rutika Titre 2015 年 12 月 2 日
Thank You sir for your help I got my answer.I used "elseif" in my code which worked. Thank you so much.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by