Borrar filtros
Borrar filtros

Find Maximum Values of a 3 Dimensional Matrix

72 visualizaciones (últimos 30 días)
ercan duzgun
ercan duzgun el 17 de Nov. de 2015
Comentada: ercan duzgun el 1 de Dic. de 2015
I need to find each maximum values (position/indexing of values) of each layer on a 3 dimensional matrix.
It was given for a two dimensional matrix.
example:
--------------------
A = [8 2 4; 7 3 9];
[M,I] = max(A(:));
[I_row, I_col] = ind2sub(size(A),I)
---------------------
Here I_row and I_col is could be found. But I need a 3 dimensional matrix's maximum indexing of each layers.
Example:
---------------------
F(:,:,1)=[8 2 4; 7 3 9];
F(:,:,2)=[7 2 1; 0 5 1];
---------------------
I need position of 9 for the 1'st layer (which is (2,3)), and also position of the 7 for the 2'nd layer (which is (2,1)).
That layers are going up to 150 or more. (F(:,:,150))
So, how can I find each of the maxsimum of the matrix?
Thanks in advance.

Respuesta aceptada

Thorsten
Thorsten el 18 de Nov. de 2015
Reshape the pages of F into separate columns, determine the max for each column and use ind2sub to convert linear indices to subscripts:
[s1 s2 s3] = size(F);
[maxval, ind] = max(reshape(F(:), s1*s2, []));
[i j] = ind2sub([s1 s2], ind);
X = [maxval' i' j'];

Más respuestas (1)

Walter Roberson
Walter Roberson el 17 de Nov. de 2015
[M,I] = max(F(:));
[I_row, I_col, I_page] = ind2sub(size(F),I)
  1 comentario
ercan duzgun
ercan duzgun el 18 de Nov. de 2015
Dear Walter Roberson,
Thanks for your answer. But this code gives the overall maximum position of the F matrix. I need the each maximum of each layer/I_page.
Your code gives the that result for this request code: ----------------
F(:,:,1)=[8 2 4; 7 3 9];
F(:,:,2)=[7 2 1; 0 5 1];
[M,I] = max(F(:));
[I_row, I_col, I_page] = ind2sub(size(F),I)
-------------------
(Command Window gives this result:) ---------------- I_row = 2 I_col = 3 I_page = 1 >> -----------------
But what I need is like that: for I_page(1); the maximum position is I_row=2 ; I_col=3 and for I_page(2); the maximum position is I_row=1 ; I_col=1.
I need the every maximum position of the each page/layer as I said before. I couldn't manage to do this.
Thank you for your response, but it doesn't work for me.
Kind regards.

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by