find min value of 1st layer of a multidimensional matrix
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Andrew Poissant
le 11 Avr 2017
Commenté : Andrew Poissant
le 11 Avr 2017
I want to find the min value of the 1st layer in an n layer matrix and I want to get the indices too. I tried messing around with min() and ind2sub() but I could not get what I was looking for. How would I got about doing this? An example matrix is seen below.
N = randi([1,500],45,45)
N(:,:,2) = randi([5,200], 45, 45)
N(:,:,3) = randi([1,50], 45, 45)
0 commentaires
Réponse acceptée
the cyclist
le 11 Avr 2017
Modifié(e) : the cyclist
le 11 Avr 2017
Here's one way:
% Set seed for reproducibility
rng 'default'
% Your array
N = rand(4,3,2);
[m,n,~] = size(N);
% Find the minimum value in the first slice.
[minValue minLinearIndex] = min(reshape(N(:,:,1),[m*n,1]));
% Convert the linear index to subscripts
[minrow mincol] = ind2sub([m,n],minLinearIndex);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Operating on Diagonal 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!