how to find non zero minimum
305 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
maryam
2014-10-4
2 个评论
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
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
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))
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)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!