Display lat lon on a variable

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 个评论

text should work just fine altho it would be useful to see a sample dataset and illustration of what you have and would like for specifics...
What I would like is for the 41x41 cape values to be displayed with longitude along the top, and latitude down the side somewhat like this:
I have the longitude and latitude both as 41x1 matrices, although these are easily made into a lon grid and lat grid
jonas
jonas 2018-8-26
编辑:jonas 2018-8-26
Do you want to build a table or a graph? What is inside of the area labelled cape?
The output does not matter as I just want to be able to see the lat lon making the cape values easier to find. The area labelled cape would be the values of cape for the corresponding lat lon. I'll insert a screenshot of the data!
For reference these are the cape values for 12pm on 28th June 2012, although I realise it has no bearing on the answer, it's useful for context. What I will need to be doing is searching for CAPE within these grids for particular lon and lat (the area is the United Kingdom, -9 to 2 degrees east, and 50 to 61 degrees north).
So just put then in a table and name the rows/cols according to the corresponding lat/lon. Would that work?
I have been trying this but as my longitude has some negative values matlab will not allow me to rename the columns, I'm trying to find a way around this but I'm stumped thus far. I have created a table with the latitude however...
Here is my table but as you can see the column names arent the longitude, and I get an error when trying to assign the numerical values to the names.
Convert to categorical and use category names for the labels.
It would make it much easier for somebody to give specific help including code snippets if you'd attach at least a subset of the data -- nothing can be done with images.
Sorry I'm very new to this, please be patient
I have column labels now using the genvarname function to convert my longitudes to acceptable variable names, it doesn't look nice but it works.
Matlab doesn't allow you to rename variables to anything but cell arrays so I think I may have to make do with this
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
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 个评论

Hi this seems to be what I need, I get an error trying to grid the cape to the matrix, namely i get an error using length "too many input variables", and from then on the griddata returns an error too.
It sounds like I'm so close to getting the grid as I need it!
jonas
jonas 2018-8-26
编辑:jonas 2018-8-26
I think Claudio meant to use size and not length. However, that line has been commanted so it shouldn't cause an error...

请先登录,再进行评论。

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 个评论

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)
Hi Claudio--imagesc does not interpolate at all. It plots the value of each pixel, scaled as color.

请先登录,再进行评论。

jonas
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

产品

版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by