How do do a pcolorm of an array with NaNs?

5 ビュー (過去 30 日間)
A LL
A LL 2022 年 1 月 13 日
回答済み: Pavan Sahith 2023 年 11 月 2 日
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! :)

回答 (1 件)

Pavan Sahith
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.

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by