Finding precipitation of specific coordinate matrix

조회 수: 2 (최근 30일)
Gokhan Kayan
Gokhan Kayan 2021년 5월 9일
댓글: Gokhan Kayan 2021년 5월 10일
Hi, I have a precipitation data that includes 3 columns. First column shows latitudes, second column shows longitudes and last one shows precipitation values. Suppose, I have A matrix:
A = 36 35 100
36 34 78
36 33 42
36 32 51
35 35 83
35 34 72
35 33 80
Here each columns show lat, lon and precipitation values of big region. But I want to extract precipitation values of specific B matrix that is shown below.
B= 36 33
36 32
35 33
so the precipitation values of that coordinates should be equal to R= 42, 51, 80. How can I wrote this code in matlab ? Thanks for your help.

채택된 답변

David Fletcher
David Fletcher 2021년 5월 9일
A = [36 35 100;
36 34 78;
36 33 42;
36 32 51;
35 35 83;
35 34 72;
35 33 80 ; ]
index=(A(:,3)==42|A(:,3)==51|A(:,3)==80)
selction=A(index,1:2)
  댓글 수: 5
David Fletcher
David Fletcher 2021년 5월 10일
편집: David Fletcher 2021년 5월 10일
You wouldn't be using all rows of the B matrix, just a specific value for each check so B(1,1) rather than B(:,1) and so on... However, I'm not sure you really want to be writing an expression of that magnitude. Since B is so large a loop may be a better idea to build the indexing matrix by iterating through each row of B and checking it against A - Something like this:
A = [36 35 100;
36 34 78;
36 33 42;
36 32 51;
35 35 83;
35 34 72;
35 33 80 ; ];
B= [36 33;
36 32;
35 33];
%Preallocate logical indexing vector to the number of rows in A. Set
%initial condition to no match (false)
positions=false(size(A,1),1);
for rowIndex=1:size(A,1)
%Check each longitude and latitude position in B against each row of A
for entries=1:size(B,1)
if (A(rowIndex,1)==B(entries,1)&&A(rowIndex,2)==B(entries,2))
%If position matches set indexing vector
positions(rowIndex)=true;
end
end
end
%Show rainfall for matching longitude and latitude entries
rainfall=A(positions,3)
Gokhan Kayan
Gokhan Kayan 2021년 5월 10일
Thanks dear David, It perfectly worked now.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Other Formats에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by