Finding values in a matrix

8 次查看(过去 30 天)
HA
HA 2020-8-18
编辑: dpb 2020-8-19
Hello,
I have two matrices, the first is a lon,lat,time (70,17,3480) matrix (A), the second is the spatial minimum of that matrix in time (1x3480) (B).
I want to loop through the 3D matrix with the 1D matrix to ultimatly find the locations of the minimum value from the 1D matrix. So basically find where in the 70x17 section the specific 3480 value is? I hope that makes sense.
I guess it wants to be some kind of loop of-
[c] = find(A==B);
I guess some kind of logical loop would do this better?
Thank you!
  1 个评论
dpb
dpb 2020-8-18
So, if I follow, the vector B is the minimum across each plane of A?
If that is the case, it would seem one would already have been able to have computed/saved that information when found the minimum much more efficiently than in doing a search/match after the fact.

请先登录,再进行评论。

回答(1 个)

Michael Soskind
Michael Soskind 2020-8-19
Hi HA,
As dpb mentioned, if you have these minima calculated by matlab, it is easier to use the computed/saved information in that case. However, another solution is to use the find method, but to match the sizes as needed. For instance, I can make a random set of 3D data (A), find the minima (B), and then find the indices of each of the values. These indices are not recalled as a row and column, but rather as a the linear index of the original three-dimensional array.
% Generating matrix of random values, size is 3x3x10 for simplicity
for i = 1:10
A(:,:,i) = rand(3,3);
end
% Calculating the minima of A, stored in matrix B, and the indices of the minima stored in Idx
[B, Idx] = min(min(A));
% 1x10 array showing all of the minima locations in the 3-D array A
C = find(A == repmat(B,[3,3,1]));
I am not exactly sure if that will work for you, or if you need the exact lat and long separately. If so, then this method probably would not work for you. However, it is an alternative that you might find useful if you really need to search for this at another time compared to calculation.
Best,
Michael
  1 个评论
dpb
dpb 2020-8-19
编辑:dpb 2020-8-19
Yeah...was hoping the comment would prompt the response to tell/show us how these were done so we could retrieve the locations then directly...it might, in fact, be faster to do that again to get the locations than the search.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by