Find the layer the minimum number occurs
Show older comments
I have a 3D array and I want to find the layer where the minimum number occurs for each row,column combination. Where the output is a 2D array of the same number of rows/columns as the input 3D array.
Accepted Answer
More Answers (1)
KALYAN ACHARJYA
on 1 Sep 2018
array=randi(10,4,4,3);
[rows colm z]=size(array);
for j=1:z;
num(j)=sum(sum(array(:,:,j)==1)+sum(array(:,:,j)==2)+sum(array(:,:,j)==3));
end
minimum_value=min(num);
idx=find(num==minimum_value);
fprintf('The Layer number is %d',idx)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!