Display lat lon on a variable
5 次查看(过去 30 天)
显示 更早的评论
I have a 41x41 grid of CAPE values for a particular time in 2012, with 41 longitude values (columns), and 41 latitude values (rows).
I was wondering if I could get the long and lat values to display with the grid of CAPE values to make it easier to read, as I'm looking mostly at CAPE during storms over very specific areas each time, but it is useful to see the values around it.
I hope this makes sense.
9 个评论
dpb
2018-8-26
Oh, yeah, to actually use table they do have to be valid variable names; I was thinking since the categories value array is cellstr array it would suffice -- but since they're all just numeric that doesn't create a valid identifier for the column variables.
Best I've got so far would be--
Lat=55:60;Lon=1:4; % small example subset
LL=meshgrid(Lon,Lat); C=rand(size(LL))*30; % sample data...
t=array2table(C); % convert to table, default names
t.Properties.VariableNames=cellstr(num2str(Lon.','Lon_%d'));
t.Properties.RowNames=categories(categorical(Lat));
t =
6×4 table
Lon_1 Lon_2 Lon_3 Lon_4
_______ ______ ______ ______
55 8.9378 21.743 2.776 4.7067
56 6.8736 5.1818 24.531 15.378
57 4.173 27.963 9.2709 5.4607
58 0.65364 29.9 6.0296 11.225
59 4.8122 25.555 16.851 19.786
60 24.993 5.9381 20.29 4.8698
The property 'VariableDescriptions' can be text string but unfortunately there doesn't seem any way to force it to be displayed except with summary function--seems to sorta' defeat the point in having it. Same limitation seems to be so with 'VariableUnits' as well.
This unfortunately won't work if the longitude values aren't integers as a floating point number couldn't be valid name, either.
Seems like enhancement request to have switch to display the annotations would be reasonable.
回答(4 个)
Claudio Iturra
2018-8-26
编辑:dpb
2018-8-26
% 1) make a grid of your longitude(lon) and latitude(lat)
% to generate the grid, you need the maximum and minimum values of longitude and latitude
[grid_lon,grid_lat] = meshgrid(min(lon):0.01:max(lon),min(lat):0.01:max(lat));
% you can check the grid with plot(grid_lon,grid_lat)
% grid_cape = nan(length(lat,1),lengh(lat,2),20);
%Finally, Grid the CAPE values to the final matrix
grid_cape = griddata(lon,lat,CAPE,grid_lon,grid_lat);
% display the gridded data!
pcolor(grid_lon,grid_lat,grid_cape);
2 个评论
Chad Greene
2018-8-26
If the cape data is already a 41x41 grid, I believe Claudio's suggestion of using meshgrid and griddata lines are unnecessary. Also, the pcolor function unfortunately discards a row and column of data, so I'd use imagesc instead. It may be as simple as this?
imagesc(lon,lat,cape)
axis xy
xlabel 'longitude'
ylabel 'latitude'
2 个评论
Claudio Iturra
2018-8-27
Hello Chad, How r u? can I ask you if imagesc use linear interpolation to make the plot?, is possible to change the interpolation like in griddata?. Thanks!
griddata(..., METHOD) where METHOD is one of
'nearest' - Nearest neighbor interpolation
'linear' - Linear interpolation (default)
'natural' - Natural neighbor interpolation
'cubic' - Cubic interpolation (2D only)
'v4' - MATLAB 4 griddata method (2D only)
Chad Greene
2018-8-27
Hi Claudio--imagesc does not interpolate at all. It plots the value of each pixel, scaled as color.
jonas
2018-8-26
编辑:jonas
2018-8-26
This seems to be what you want to have. Just replace lat, lon and the input data with your own.
t=uitable('data',randi(40,40))
lat=1:40;
lon=-40:-1;
LAT=sprintfc(['%g',char(176)],lat)
LON=sprintfc(['%g',char(176)],lon)
t.ColumnName = LAT
t.ColumnEditable = true;
t.RowName = LON
t.ColumnEditable = true;
set(t,'units','normalized','position',[0 0 1 1])
See attachment for results
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Geographic Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!