How to find the minimum of each layer of a 3d array, then the maxima of those values and it's location in the original matrix
5 views (last 30 days)
Show older comments
I have a 3d array of R values for a composite laminate code I am working on. Each layer of the array it a 3x2 matrix, and I need to find the minimum value of each layer, then the maximum value of these minima. Aditionally I need to know the location of this final value in the original matrix. Currently I am using the code below, but this provides the overall highest value.
[va,loc] = max(Rf(:));
v=max(va);
[ii,jj,k] = ind2sub(size(Rf),loc);
if ii == 1
i='1';
elseif ii == 2
i='2';
elseif ii == 3
i = '12';
end
if jj == 1
j = 'Bottom';
elseif jj ==2
j = 'Top';
end
disp(['The maximum R value was found to be ',num2str(v),' in the ', i, ' direction at the ', j, ' of ply ', num2str(k)])
0 Comments
Answers (1)
VINAYAK LUHA
on 5 Dec 2023
Edited: VINAYAK LUHA
on 5 Dec 2023
Hi Jocab,
I understand that you have a 3D matrix where each layer is of size 3x2, and you want to find the minium value within each layer and subsequently the maximum value of these minimum values.Further you want to locate the index of maximum value obtained in the original array.
Here is the code with explanation to achieve the above functionality -
arr3D = randn(3, 2, 5);
% Find the minima in each layer
min_values = min(arr3D, [], [1 2]);
% Find the maxima of the minimas
[max_of_minima, layer_index] = max(min_values, [], 'all', 'linear');
% Find index of the maxima in the maxima layer
[x,y] = find(arr3D(:,:,layer_index) == max_of_minima);
disp('Layer minimas:');
disp(min_values);
disp(['Maxima of layer minimas: ', num2str(max_of_minima)]);
disp(['Index of maxima: ', num2str(x),",",num2str(y),",",num2str(layer_index)]);
Hope this solves your query.
Regards,
Vinayak Luha
0 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!