how to find non zero minimum

404 vues (au cours des 30 derniers jours)
maryam
maryam le 4 Oct 2014
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

Réponse acceptée

maryam
maryam le 4 Oct 2014
this is simple :) name the matrix A (for example) then : m=min(A(A>0)); m returns the non zero minumum
  2 commentaires
Charanraj
Charanraj le 1 Déc 2019
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 le 9 Fév 2024
Modifié(e) : Selina KOLOKYTHA le 9 Fév 2024
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.

Connectez-vous pour commenter.

Plus de réponses (2)

Zoltán Csáti
Zoltán Csáti le 4 Oct 2014
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 commentaire
maryam
maryam le 4 Oct 2014
thank you so much

Connectez-vous pour commenter.


Erick Medina
Erick Medina le 28 Nov 2017
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)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by