Row and column of minim value from 3D matrix
조회 수: 11(최근 30일)
I've been looking for a method to do this since yesterday. I found some helpful answers here and the one which helps me the most still does not give me the best result.
I am trying to find the row and column of a matrix A = (:,:,eachUser) .
The column values are the one I need but the row values are totally different from what I have to obtain, unless the first one ( out of 10) which is always ok.
Any suggestions would be much appreciated. Thanks!
LE: I have the matrix A(row,column,User) and for each User I have the rows and columns. I want the minimum value from each row x column for each USER and it's index in order to calculate the exact position in the A matrix.
for eachUser = 1:length(Users_coordinates)
UsersDistance(:,:,eachUser) = ManhattanDistanceSum_2(:,:,eachUser);
[minimumV2(:,:,eachUser) , indexMinimSecond(:,:,eachUser)] = min(minimumV1(:,:,eachUser));
rowV2(:,:,eachUser) = ind2sub(size(UsersDistance(:,:,eachUser)),indexMinimFirst(indexMinimSecond(:,:,eachUser)));
columnV2(:,:,eachUser) = ind2sub(size(UsersDistance(:,:,eachUser)),indexMinimSecond(:,:,eachUser));
% ErrorPositioning(eachUser) = myerrordistance(row(:,:,eachUser),Users_coordinates(eachUser,1), col(:,:,eachUser),Users_coordinates(eachUser,2));
dpb 2021년 7월 15일
편집: dpb 2021년 7월 15일
I'm going to shorten variable names...
nP=size(X,3); % number planes in array X
r=zeros(nP,1); c=r; % preallocate output rows,columns arrays
for i=1:nP % iterate over planes of 3D array X
[mn,imn]=min(X(:,:,i),,'all','linear'); % get minimum, location global minimum over plane of X
[r(i),c(i)]=ind2sub(size(X,1,2),imn); % return row,col indices of minimum in plane
This gives the overall minimum location for each plane; by default as your code is written you get the minimums in each column so that is size(X,2) elements but the index is then the row of each column.
That's also convertible to absolute position if that is what is wanted but it isn't clear from the post.