フィルターのクリア

Finding lowest value and the index from vector excluding zero and inf

2 ビュー (過去 30 日間)
Mark Sc
Mark Sc 2021 年 2 月 18 日
コメント済み: Star Strider 2021 年 2 月 18 日
Hi all,
I am trying to find lowest number excluding zero and inf from a vector:
I wanna the output to be:
r= 0.5
index= 6
I tried the following but it does not give me what I want:
clearvars
clc;
x = [1 3 2;-1 inf 0.5];
[r,index] = find (min(x(:)>0));

採用された回答

Star Strider
Star Strider 2021 年 2 月 18 日
Try this:
x = [1 3 2;-1 inf 0.5];
[r,index] = min(x(x>0))
producing:
r =
0.5
index =
5
The find call is not necessary here.
  2 件のコメント
Mark Sc
Mark Sc 2021 年 2 月 18 日
Thanks for your answer.
The r is correct however, index should be 6..
As I would like to do x as vector , do not understand why index = 5 not 6 ?
clearvars
clc;
x = [1 3 2;-1 inf 0.5];
y = x(:);
[r,index] = min(y(y>0))
Star Strider
Star Strider 2021 年 2 月 18 日
My pleasure!
I disagree.
See: Indexing with a Single Index for a discussion of MATLAB matrix indexing conventions.

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

その他の回答 (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