Need 3rd dimension indicies for calling values.

조회 수: 2 (최근 30일)
Steven
Steven 2015년 2월 17일
댓글: Steven 2015년 2월 18일
I am trying to find the value in one three dimensional array that corresponds to the location of a maximum in another.
In my case I have a variable called "N2s" and "avg_dye03". both of these have the same dimension of 340x291x20.
I first found the indicies of the third dimension maximum of N2s via the following...
index=find(max(N2s,[],3));
I then use index to call the values of avg_dye03 that correspond to the third dimensional maximum of N2s via...
avg_dye03(index)
My issue is that this returns a 1 dimension array with dimensions 98935x1.
I want the values of avg_dye03 that correspond to the third dimension maximum of N2s to have dimensions of 340x291x1 (same as if I just did max(N2s,[],3)).
I've tried using ind2sub, but the I constantly get a value of 1 for the third dimensional index (1st and 2nd dimensional indicies seem ok). Further more, generating a 340x291x1 matrix using the three indicies from ind2sub would require a tedious set of for loops that I haven't got patience or resources to run.
Any help with this would be greatly appreciated.

채택된 답변

James Tursa
James Tursa 2015년 2월 17일
편집: James Tursa 2015년 2월 17일
m = size(N2s,1);
n = size(N2s,2);
[~,x] = max(N2s,[],3); % 3rd dimension indexes of the max locations
y = (1:m*n)' + (x(:)-1)*(m*n); % linear index of these locations in full array
result = reshape(avg_dye03(y),m,n); % use linear indexing, then reshape result

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by