using if, else-if and else

4 ビュー (過去 30 日間)
Augustine Onafeko
Augustine Onafeko 2015 年 4 月 16 日
コメント済み: Augustine Onafeko 2015 年 4 月 16 日
Hi i am trying to figure out how i can use if, elseif and else to find the first value in an array to fall below the value 5, any help understanding how this can be done would be appreciated.
thanks
  1 件のコメント
James Tursa
James Tursa 2015 年 4 月 16 日
Please show the code you have written so far and we can comment on it and make suggestions.

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

採用された回答

pfb
pfb 2015 年 4 月 16 日
編集済み: pfb 2015 年 4 月 16 日
If I get it right, you have an array and you want to find its first value (index-wise) less than 5. If this is the case, and there is no particular reason forcing you to use "if", "then" and "else", then you can achieve this very easily. Assuming that your vector is called v, the index of the element you are looking for is
i = min(find(v<5));
Note that if all the elements of v are >= 5, the instruction
find(v<5)
will output an empty vector "[]", and the same will do the "min" function. Therefore, you'll get
i = []
  1 件のコメント
Augustine Onafeko
Augustine Onafeko 2015 年 4 月 16 日
Thanks a lot

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by