How do do a pcolorm of an array with NaNs?
조회 수: 1 (최근 30일)
이전 댓글 표시
I exported a mask from a coarser resolution to a finer resolution grid.
The grid with finer resolution is a lon x lat grid of size 1440x121 covering my domain.
I want to do a pcolorm(lat,lon,Z) over the region covering this given mask.
Since the mask is from a coarser resolution, the lat, lon and Z over the mask are filled with NaN and I can't get pcolorm to work properly.
I have:
-latitude (updownLat) and longitude (updownLon) coordinates for my points of interest (mask);
-the corresponding pressure values at each point of interest (mslp1Arctic);
-1440x121 matrix for the latitude at each grid cell (latMat);
-1440x121 matrix for the longitude at each grid cell (lonMat);
-1440x121 matrix with pressure values at each grid cell (mslp1);
-1440x121 matrix with the latitude values only at the coordinates of the points of interest and NaN elsewhere (latMatMask);
-1440x121 matrix with the longitude values only at the coordinates of the points of interest and NaN elsewhere (lonMatMask);
-1440x121 matrix with the pressure values only at the coordinates of the points of interest and NaN elsewhere (mslp1Mask);
I wish to plot a pcolorm(latMatMask,lonMatMask,mslp1Mask) with all the mslp1 values in the region covered by the mask.
% Figure I want to do
figure(1);
hold on;
axesm('MapProjection','eqdazim','MapLatLimit',[60 90]);
axis off;
framem on;
gridm on;
mlabel on;
plabel on;
setm(gca,'MLabelParallel',0);
%plotm(updownLat,updownLon,'.'); %Domain where I want to do the pcolorm (mask)
%pcolorm(latMatMask,lonMatMask,mslp1Mask); %NOT WORKING
%colormap(parula);
%cb = colorbar;
geoshow('landareas.shp','FaceColor',"none",'LineWidth',1);
axis off;
set(gca,'Fontsize',15);
gcf;
I have attached an image for a better visualisation of what I wish to do (matlabQuestion.png).
Thank you! :)
댓글 수: 0
답변 (1개)
Pavan Sahith
2023년 11월 2일
Hello,
I understand that you are attempting to use the "pcolorm" function, but your array contains NaN values at points that are not of interest.
To filter out these NaN values, you can refer to the code snippet provided below:
%Removing all the NaN values from the array
latNew=latMatMask(~isnan(latMatMask));
lonNew=lonMatMask(~isnan(lonMatMask));
mslp1MaskNew=mslp1Mask(~isnan(mslp1Mask));
pcolorm(latNew,lonNew,mslp1MaskNew);
Please refer to the following MathWorks documentation.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!