Hi, I have 3 2d arrays with same dimensions(or a 3d array with 3 layers), and I want to find the the minimum position of each point. e.g. function could tell which array (or layer has the minimum value of each point).
I know how to do that with for loop, but that cost a lot of time dealing with large scale arrays. So is there a more efficient way to do that?
D=rand(1000,1000,3); [row,col,~]=size(D); for i=1:row for j=1:col close=min(D(i,j,:)); %minimum value
if size(find(D(i,j,:)==close))==1 %if only one minimum
position(i,j)=(find(D(i,j,:)==close)); else n=find(D(i,j,:)==close); %if 2 or more
position(i,j)=n(1); end end end
Best Answer