Find the maximum in my array

Hello, I have an array of size x,y,z. Now, I would like to locate the maximum within all the values in the array. I want to know the value of x, y and z for this maximum value. Thank you very much in advance for your help!

 Respuesta aceptada

Jan
Jan el 14 de Mzo. de 2017
Editada: Jan el 14 de Mzo. de 2017

2 votos

A = rand(x, y, z);
[maxValue, maxIndex] = max(A(:));
[ix, iy, iz] = ind2sub([x, y, z], maxIndex);
[EDITED] Here "A" was created only as test data only. If you have the array already, you need the size() command to obtain the dimensions:
[maxValue, maxIndex] = max(A(:));
[ix, iy, iz] = ind2sub(size(A), maxIndex);

3 comentarios

Auryn_
Auryn_ el 14 de Mzo. de 2017
Thank you! However, how do I do it when I have already A (in you answer you define it randomly). If I used what you send it is asking me to define x,y,z. I tried [maxValue, maxIndex] = max(A(:,:,:)); [ix, iy, iz] = ind2sub([A(:,:,:)], maxIndex); but it doesn't work. Thanks in advance for your help.
Jan
Jan el 14 de Mzo. de 2017
See [EDITED]. Not that "A(:)" is a vector, while "A(:, :, :)" is not and the shown method does not work.
Auryn_
Auryn_ el 14 de Mzo. de 2017
Thanks!

Iniciar sesión para comentar.

Más respuestas (1)

Auryn_
Auryn_ el 14 de Mzo. de 2017

0 votos

Hi again,
I have an additional question. Can I use something similar to find the values within a range (e.g. between 0 and 1)? Thanks in advance.

2 comentarios

Jan
Jan el 14 de Mzo. de 2017
Please open a new thread for a new question to avoid confusing the readers. Thanks.
The answer might be something like:
Index = find(0 < A & A < 1);
[ix, iy, iz] = ind2sub(size(A), Index)
Sigh, now I've answered already. So obviously I'm the first person who is confused ;-)
Auryn_
Auryn_ el 14 de Mzo. de 2017
Thanks, and sorry for the confusion :)

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 14 de Mzo. de 2017

Comentada:

el 14 de Mzo. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by