Need 3rd dimension indicies for calling values.

2 次查看(过去 30 天)
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