필터 지우기
필터 지우기

Plot data for a for specific x and y coordinates

조회 수: 10 (최근 30일)
dylan price
dylan price 2018년 6월 18일
댓글: Chandra Shekhar Lohani 2022년 11월 28일
I have some data indicating precipitation at various coordinates in the world that I would like to plot. Each horizontal line is a combination of longitude (170...), lattitude (-72...) and precipitation (2...).
170.5 -72.5 2.11
171.5 -72.5 3.16
172.5 -72.5 2.69
173.5 -72.5 2.79
174.5 -72.5 2.41
I would like to plot the precipitation values for each set of xy coordinates as a chart with a colour scale varying for the precipitation amount. ie. x axis would be longitude, y axis lattitude and the chart would have multitude of different coloured points at their respective xy locations.
I have tried:
lat=dition;
lon=HDRAd;
data=al_ProcessingMap_Area_Averages_Removed;
lon=str2double(lon);
[lon,lat,data]=meshgrid(lon,lat,data);
surf(lon,lat,data)
which returns Error using repmat Maximum variable size allowed by the program is exceeded.
Error in meshgrid (line 77) xx = repmat(xx, ny, 1, nz);
Error in ecco (line 24) [lon,lat,data]=meshgrid(lon,lat,data);
The same thing with a truncated dateset yields this:
lat=dition;
lon=HDRAd;
data=al_ProcessingMap_Area_Averages_Removed;
lon=str2double(lon);
lon=lon(1:10)
lat=lat(1:10)
data=data(1:10)
[lon,lat,data]=meshgrid(lon,lat,data);
surf(lon,lat,data)
Error using matlab.graphics.chart.primitive.Surface/set Value must be a vector or 2D array of numeric type
Error in matlab.graphics.chart.internal.ctorHelper (line 6) set(obj, pvpairs{:});
Error in matlab.graphics.chart.primitive.Surface
Error in surf (line 150) hh = matlab.graphics.chart.primitive.Surface(allargs{:});
Error in ecco (line 12) surf(lon,lat,data)
I have also tried
map=pcolor(lon,lat,data)
to no avail. It feels like such a simple problem that I'm struggling with! Any help is much appreciated
  댓글 수: 2
Rik
Rik 2018년 6월 18일
It looks like you need to reshape the data, not use meshgrid. You already have all (x,y,z) pairs, so you only need to put it in a shape that surf likes. If you attach a .mat with your data we can help you with reshape. You can also show some code that will generate similarly shaped data.
dylan price
dylan price 2018년 6월 18일
Thanks for the tip, I'll have a look at reshape. I've attached a .mat file

댓글을 달려면 로그인하십시오.

채택된 답변

Rik
Rik 2018년 6월 18일
You have holes in your data (i.e. not all grid positions have data). Therefore surf will not work. You can either choose to plot the data itself, or interpolate it. The code below shows how to do either.
lat=dition;
lon=str2double(HDRAd);
data=al_ProcessingMap_Area_Averages_Removed;
[lat_q,lon_q]=meshgrid(unique(lat),unique(lon));
F = scatteredInterpolant(lat,lon,data);
interpolated_data=F(lat_q,lon_q);
figure(1),clf(1)
%if you want to show the actual data itself as a scatterplot:
%plot3(lat,lon,data,'.'),hold on
surf(lat_q,lon_q,interpolated_data)
  댓글 수: 2
dylan price
dylan price 2018년 6월 18일
Thank you! It would have taken me ages to figure this out
Chandra Shekhar Lohani
Chandra Shekhar Lohani 2022년 11월 28일
Thanks a lot Rik

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Afshin Aghayan
Afshin Aghayan 2019년 10월 8일
you can use this code for displaying any data in the form of [x, y, f(x,y)] or data with coordinate

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by