Finding precipitation of specific coordinate matrix
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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
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)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Other Formats 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!