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 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
VINAYAK LUHA
2023 年 12 月 5 日
編集済み: VINAYAK LUHA
2023 年 12 月 5 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!