Getting lowest postive number in array with it's index

4 ビュー (過去 30 日間)
Mark Sc
Mark Sc 2021 年 3 月 21 日
コメント済み: Stephan 2021 年 3 月 21 日
Hi,
I am trying to get lowest postive number from array , and it's index,
I got the correct lowest postive number but due to introducing of greater than sign >, the indicies numbering changed, can anyone tell me how could I obtain lowest postive number with keeping and getting correct index...
I attach the code below... (Please remember it's a part from a code, and i need to get the values as written below)
clearvars;
clc;
S=[-6.3e7 -0.0001e7 inf;5.2545 -.2996e7 inf];
[m,idx]=min(S(S(:)>0)); % THE RESULT IS CORRECT BUT INDEX IS WRONG ... INDEX SHOULD BE 2
% I UNDERSTAND NOW THE INDEX IS CHANGED AS I INTRODUCED >0 BUT I WOULD LIKE TO GET THE INDEX FROM S(:) NORMAL

採用された回答

Stephan
Stephan 2021 年 3 月 21 日
編集済み: Stephan 2021 年 3 月 21 日
S=[-6.3e7 -0.0001e7 inf;5.2545 -.2996e7 inf]
m_idx = [min(S(S>0)), find(S==min(S(S>0)))]
  2 件のコメント
Mark Sc
Mark Sc 2021 年 3 月 21 日
Thanks for your answer...
It works, however, I need to have the output as two separate varaibales,
any suggestions??
I would use
min_val=m_idx(1);
idx=m_idx(2)
but if you have a direct way to obtain such thing, please share
but anyway.. thank you so much
Stephan
Stephan 2021 年 3 月 21 日
S=[-6.3e7 -0.0001e7 inf;5.2545 -.2996e7 inf]
[m, idx] = myFun(S)
function [m, idx] = myFun(S)
m = min(S(S>0));
idx = find(S==min(S(S>0)));
end

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by