Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Finding max value and its position in ed matrix

11 vues (au cours des 30 derniers jours)
Lucrezia Cester
Lucrezia Cester le 27 Nov 2019
Clôturé : MATLAB Answer Bot le 20 Août 2021
Hello,
I know this question has alreayd been asked a million times, yet I have not managed to solve it by looking at previous documentation.
I have a 3d matrix. I want to find the max value in each "page" (max of 1st and 2nd dimension) along the third dimension. And I also want to know the indeces of the value.
Here is my attempt at the code.
C is my 3d matrix i want to get the max values from.
Cmax = zeros(1,numkx);
row = zeros(1,numkx);
column = zeros(1,numkx);
for c = 1 : numkx
Cpage(:,:,c)= C(:,:,c);
Cmax(:,:,c) = max(Cpage(:));
[row,column] = find(Cpage(:) == Cmax(1,c));
end

Réponses (1)

Andrei Bobrov
Andrei Bobrov le 27 Nov 2019
Modifié(e) : Andrei Bobrov le 27 Nov 2019
[m,~,k] = size(C);
[C_max_of_page,i] = max(reshape(C,[],k));
index_of_C_max_of_page = [mod(i-1,m)+1; ceil(i/m); (1:k)];
  2 commentaires
Lucrezia Cester
Lucrezia Cester le 27 Nov 2019
Modifié(e) : Lucrezia Cester le 27 Nov 2019
This seems to give the max values in a increasing order. It basically tells me 1 at position row = x, column = y, then 2 is at position....etc.
I wanted to know the max value of each page of the 3d matrix instead.
Andrei Bobrov
Andrei Bobrov le 27 Nov 2019
Modifié(e) : Andrei Bobrov le 27 Nov 2019
I'm fixed answer.
>> C = randi(120,3,3,3)
C(:,:,1) =
19 46 58
103 23 15
78 52 71
C(:,:,2) =
28 31 32
47 35 99
70 75 118
C(:,:,3) =
88 13 99
42 109 32
71 106 72
>> [m,~,k] = size(C);
[C_max_of_page,i] = max(reshape(C,[],k))
index_of_C_max_of_page = [mod(i-1,m)+1; ceil(i/m); (1:k)]
C_max_of_page =
103 118 109
i =
2 9 5
index_of_C_max_of_page =
2 3 2
1 3 2
1 2 3
>>

Cette question est clôturée.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by