14 views (last 30 days)

I want to plot gridded latitude and longitude as pixels on the map, Latitude is 1 x 32 and longitude is 1 x 40 I don't know how to this I tried geoshow but it said latitude and longitude must have the same size.

Error using checklatlon (line 25)

Function GEOSHOW expected its first and second input arguments,

LAT and LON, to match in size.

Error in geovecshow (line 37)

checklatlon(lat, lon, 'GEOSHOW', 'LAT', 'LON', 1, 2);

Error in geoshow (line 278)

h = showFcn(varargin{:});

I attache latitude and longitude. latitude and longitude are taken from the NetCDF file for gridded precipitation data, but I just want to plot its pixels and I don't need precipitation data.

I want to plot them on this map:

Code to generate map:

% Produce the map

borders('Iran Islamic Republic of') % borders is a function from Matlab file exchange by Chad A Greene (https://www.mathworks.com/matlabcentral/fileexchange/50390-borders)

grid on

axis equal % I added this, important to maintain aspect ratio (@AD)

xlabel('Longitude')

ylabel('Latitude')

xtickangle(90)

I want to plot the pixels like this: (ignore the color bar and colors I just want pixels)

Thank you

Giuseppe Inghilterra
on 16 Feb 2020

I obtain this result:

by running the following code:

load lati.mat

load loni.mat

[LONG, LAT] = meshgrid(loni,lati);

Z = rand(length(lati),length(loni));

figure

surface(LONG, LAT, Z)

colorbar

xlabel('Longitude')

ylabel('Latitude')

xticks(loni)

yticks(lati)

xtickangle(90)

grid on

ax = gca;

ax.XAxis.FontSize = 7;

ax.YAxis.FontSize = 7;

In my example I generate ramdomly Z matrix, instead you should have a matrix with data in function of latitude and longitude coordinates. From your plot I see that some "pixels" are blank. This means that you can fill Z matrix with NaN values, in this way you obtain easily blank pixels.

Giuseppe Inghilterra
on 16 Feb 2020

See the following code:

- I define a circumference in x,y coordinates;
- then I evaluate if LONG,LAT coordinates are inside the defined circumference through "inpolygon" matlab function and I set to zero these entries of Z matrix;
- then I take the current colormap cmap and redefine the first line with [1 1 1]. In this way I assign color white to "zero" value and then I update colormap;

load lati.mat

load loni.mat

t = 0:pi/10:2*pi; %(1)

x = 55 + 5*cos(t);

y = 30 + 5*sin(t);

[LONG, LAT] = meshgrid(loni,lati);

Z = rand(length(lati),length(loni));

Z(inpolygon(LONG,LAT,x,y)) = 0; %(2)

figure

surface(LONG, LAT, Z)

cmap = colormap; %(3)

cmap(1,:) = [1 1 1];

colormap(cmap)

colorbar

xlabel('Longitude')

ylabel('Latitude')

xticks(loni)

yticks(lati)

xtickangle(90)

grid on

ax = gca;

ax.XAxis.FontSize = 7;

ax.YAxis.FontSize = 7;

I obtain the following resul:

Now, instead of circumference, if you have (x,y) coordinates of your curve, you can obtain the same result.

If you assign to NaN values through inpolygon function Z matrix entries, you don't need to define a custom colormap.

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.