How can I select data in a pcolor plot by using a rectangle?

5 views (last 30 days)
I am working with netcdf data to display a weather radar file. I used the pcolor function pcolor(X,Y,C) to plot the matrix of X and Y with the matrix data in C. I converted the X and Y data to cartesian from polar to make it easier to select data. The X and Y in the figure are distance in km from the center of the radar site.
My issue arises where I need to select a smaller portion of the data and only use that for analysis. I want to select from a center point specified as X and Y from the figure and select data that is in a 5x5km box broken up into 4 quadrants around the center point that I have specified. I have tried creating 4 rectangles around the selected data, but I do not know how to tell matlab to display a pcolor image of only of those rectangles. Is there a way to tell matlab to use only what is inside the rectangles for analysis? I have posted my code below with the result. Thanks!
nc=netcdf.open('C:\Users\james\Desktop\Thesis\23May2011NetCDFs\Lowest Elevation\ncswp_RaXpol_20110523_232645.602_u17_s130_4.0_SUR_.nc','NC_NOWRITE');
ZC=netcdf.getVar(nc,netcdf.inqVarID(nc,'DBZ'));
ZCdouble = double(ZC);
Ind=find(ZCdouble>30000);
ZCdouble(Ind)=NaN;
Ind1=find(ZCdouble<=0);
ZCdouble(Ind1)=NaN;
ZCdouble=ZCdouble./100;
DRC=netcdf.getVar(nc,netcdf.inqVarID(nc,'ZDR'));
DRCdouble = double(DRC);
IndZ=find(DRCdouble>30000);
DRCdouble(IndZ)=NaN;
INDZDR=find(DRCdouble<=-1000);
DRCdouble(INDZDR)=NaN;
Ind7=find(DRCdouble>1000);
DRCdouble(Ind7)=NaN;
DRCdouble=DRCdouble./100;
el= netcdf.getVar(nc,netcdf.inqVarID(nc,'Elevation')); %Elevation angle (deg)
[dimname, num_gates] = netcdf.inqDim(nc,netcdf.inqDimID(nc,'maxCells')); %number of range gates, find from the maxcells var in 'dimensions' of ncdump
delr=netcdf.getVar(nc,netcdf.inqVarID(nc,'Cell_Spacing')); %space between gates (m)
r_min=netcdf.getVar(nc,netcdf.inqVarID(nc,'Range_to_First_Cell')); %Distance to first range gate (m)
az_set=netcdf.getVar(nc,netcdf.inqVarID(nc,'Azimuth'));
el_rad = el/180*pi;
az_rad = az_set/180*pi;
phi_ref=0;
[r,az_rad] = meshgrid(((0:num_gates-1)*delr+r_min)/1e3,az_rad);
x2 = r.*cos(el_rad).*sin(az_rad); %MATRIX DIMENSIONS MUST AGREE
y2 = r.*cos(el_rad).*cos(az_rad);
z2 = r.*sin(el_rad);
Range = r(1,:);
[YCart,XCart] = pol2cart(az_rad,Range);
%centerXY = centerdata;
% plot the power in dBZ with a map overlay
figure (1);
XCenter = -8.4281;
YCenter = 7.1656;
newX = XCart';
newY = YCart';
Zfig = pcolor(newX,newY,ZCdouble);
hold on
%Specify 4 rectangle positions from center
toprightZ=rectangle('Position',[XCenter YCenter 5.0000 5.0000]);
topleftZ=rectangle('Position',[XCenter-5 YCenter 5 5]);
bottomrightZ=rectangle('Position',[XCenter YCenter-5 5 5]);
bottomleftZ=rectangle('Position',[XCenter-5 YCenter-5 5 5]);
set(Zfig, 'ZData', get(Zfig,'CData')); %Makes the data values show up in the data cursor as Z
caxis([0 55])
shading flat
colorbar
xlabel('Zonal Distance (km)')
ylabel('Meridional Distance (km)')
title('Reflectivity Factor (dBZ)')
ZYdata=Zfig.YData;
ZXdata=Zfig.XData;
ZZdata=Zfig.ZData;

Answers (1)

KSSV
KSSV on 1 Aug 2019
Read about interp2.
Fix your (Xi,Yi) for which you want to extract the data and use interp2. Something like below:
xi = linspace(xval0,yval1,m) ; % the value of x you want
yi = linspace(yval0,yval1,n) ; % the value of y you want
[Xi,Yi] = meshgrid(xi,yi) ;
Zi = interp2(X,Y,C,Xi,Yi) ;
  4 Comments
James Foster
James Foster on 2 Aug 2019
I cannot post the data because it is privately owned. That is also the entire code that I am using. I am confused what the interp2 function does. What does it do exactly in the code you posted?
KSSV
KSSV on 2 Aug 2019
[X,Y,Z] = peaks(100) ;
pcolor(X,Y,Z)
shading interp ; colorbar
% Say I want to pick data from (-2,-2) to (2,2)
[Xi,Yi] = meshgrid(-2:2,-2:2) ;
Zi = interp2(X,Y,Z,Xi,Yi) ;
figure
pcolor(Xi,Yi,Zi)
shading interp

Sign in to comment.

Categories

Find more on Geographic Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!