Find the maximum in my array

조회 수: 2 (최근 30일)
Auryn_
Auryn_ 2017년 3월 14일
댓글: Auryn_ 2017년 3월 14일
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!

채택된 답변

Jan
Jan 2017년 3월 14일
편집: Jan 2017년 3월 14일
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
Jan
Jan 2017년 3월 14일
See [EDITED]. Not that "A(:)" is a vector, while "A(:, :, :)" is not and the shown method does not work.
Auryn_
Auryn_ 2017년 3월 14일
Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Auryn_
Auryn_ 2017년 3월 14일
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
Jan
Jan 2017년 3월 14일
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_ 2017년 3월 14일
Thanks, and sorry for the confusion :)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by