Plot grided latitude and longitude as pixels on map
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
BN
el 16 de Feb. de 2020
Editada: Giuseppe Inghilterra
el 16 de Feb. de 2020
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
0 comentarios
Respuesta aceptada
Giuseppe Inghilterra
el 16 de Feb. de 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.
2 comentarios
Giuseppe Inghilterra
el 16 de Feb. de 2020
Editada: Giuseppe Inghilterra
el 16 de Feb. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Orange en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!