how to find non zero minimum

319 ビュー (過去 30 日間)
maryam
maryam 2014 年 10 月 4 日
編集済み: Selina KOLOKYTHA 2024 年 2 月 9 日
hi, i have a [8200,1] matrix with zero and positive values. i need to find non zero minimum. please guide me if you can

採用された回答

maryam
maryam 2014 年 10 月 4 日
this is simple :) name the matrix A (for example) then : m=min(A(A>0)); m returns the non zero minumum
  2 件のコメント
Charanraj
Charanraj 2019 年 12 月 1 日
Ho to do this columnwise. For example, I have 200 columns and I need to find in each column the minimum non zero. Thanks
Selina KOLOKYTHA
Selina KOLOKYTHA 2024 年 2 月 9 日
編集済み: Selina KOLOKYTHA 2024 年 2 月 9 日
Hi! Here you go:
% if A is your matrix
C=200 % number of columns
for i=1:C % for each column i
B=A(:,i); % assign each column of A to B
m(i)=min(B(B>0)); % m returns the non zero minumum of each column i
end
Note that this only works if matrix A has zero to positive values - not if it has negative values.

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

その他の回答 (2 件)

Zoltán Csáti
Zoltán Csáti 2014 年 10 月 4 日
Lets suppose your matrix is called A. Then you first select those elements that are non-zero (i.e. positive) and after that use the min function:
min(A(A > 0))
  1 件のコメント
maryam
maryam 2014 年 10 月 4 日
thank you so much

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


Erick Medina
Erick Medina 2017 年 11 月 28 日
Declare a temp_variable which is a copy of your target vector and delete all indexes equal to zero.
temp_vec = vec; temp_vec(temp_vec==0) = []; min(temp_vec)

カテゴリ

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