How to plot spatial data

5 ビュー (過去 30 日間)
Matteo Monzali
Matteo Monzali 2022 年 9 月 19 日
回答済み: Benjamin Kraus 2022 年 9 月 19 日
Hi, I would like to plot some spatial data.
In particular, I have three variables,
lat 81x1 single
lon 241x1 single
u 241x81 double
I have another code from a uni course, but the variable dimension where different. So I tried to change it and obtained the code reported.
fig2=figure('units','normalized','outerposition',[0.5 0.5 0.4 0.55]);
hold on
worldmap([double(min(lat)) double(max(lat))], [double(min(lon)) double(max(lon))]);
plot(lat,lon, u)
But I get the error:
Error using plot Vectors must be the same length.
Error in ERA5 (line 22) plot(lat,lon, u)
Could you help me please? Thank you!

回答 (1 件)

Benjamin Kraus
Benjamin Kraus 2022 年 9 月 19 日
As the error says, lat and lon need to be the same size.
Based on the shape of your variables, I suspect you need to use meshgrid to convert your variables from vectors to matrices. Something like this:
[LAT, LON] = meshgrid(lat, lon);
plot(LAT(:), LON(:), u(:))

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by