find the minmum value in each column of a matrix
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
i have the below matrix(d) and i want to find the minumum value of each column but that value must not equal to zero
d=
0 10.1164 0 0 0
11.4474 0 0 0 0
0 14.8026 0 0 0
0 0 0 0 17.4658
0 0 5.3885 0 0
13.7349 0 0 0 0
0 0 0 14.9564 0
0 0 10.7354 0 0
0 0 0 0 18.0236
0 0 0 17.2189 0
0 commentaires
Réponse acceptée
Rik
le 11 Avr 2022
If you set all values of 0 to NaN, you can do this simply with the min function.
A=[ 0 10.1164 0 0 0
11.4474 0 0 0 0
0 14.8026 0 0 0
0 0 0 0 17.4658
0 0 5.3885 0 0
13.7349 0 0 0 0
0 0 0 14.9564 0
0 0 10.7354 0 0
0 0 0 0 18.0236
0 0 0 17.2189 0];
A(A==0)=NaN;
min(A)
Plus de réponses (1)
Mathieu NOE
le 11 Avr 2022
hello
try this :
d=[ 0 10.1164 0 0 0;
11.4474 0 0 0 0;
0 14.8026 0 0 0;
0 0 0 0 17.4658
0 0 5.3885 0 0;
13.7349 0 0 0 0;
0 0 0 14.9564 0;
0 0 10.7354 0 0;
0 0 0 0 18.0236;
0 0 0 17.2189 0];
for ci = 1:size(d,2)
tmp = d(:,ci);
ind_non_zero = find(tmp>0);
[val(ci),ind] = min(tmp(ind_non_zero));
ind_final(ci) = ind_non_zero(ind);
end
val % min value (column direction)
ind_final % corresponding row position
2 commentaires
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!