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 Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by