Finding precipitation of specific coordinate matrix
    6 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Gokhan Kayan
 am 9 Mai 2021
  
    
    
    
    
    Kommentiert: Gokhan Kayan
 am 10 Mai 2021
            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 Kommentare
Akzeptierte Antwort
  David Fletcher
      
 am 9 Mai 2021
        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 Kommentare
  David Fletcher
      
 am 10 Mai 2021
				
      Bearbeitet: David Fletcher
      
 am 10 Mai 2021
  
			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)
Weitere Antworten (0)
Siehe auch
Kategorien
				Mehr zu Geodesy and Mapping finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

