The size of X must match the size of Z or the number of columns of Z.

73 vues (au cours des 30 derniers jours)
Jonas Damsbo
Jonas Damsbo le 10 Oct 2018
Commenté : Jonas Damsbo le 10 Oct 2018
Hi there
I have a netcdf file I have running in MatLab. But I want to plot contour lines for the geostrophic wind. When I running my code i got the fail "The size of X must match the size of Z or the number of columns of Z." Someone there could help me?
if true
figure(2);
clow=4680; chigh=6000; cint=60;
conts = [clow:cint:chigh];
V = [clow:cint*2:chigh];
[c,h]=contour(lat,lon,z,conts,'linewidth',1.5,'color','k');
clabel(c,h,V);
quiver(latv,lonv,vg500,ug500)
title('Geopotential height and geostrophic wind at 500 hPa')
xlabel('longitude'), ylabel('latitude')
figure(3)
clow=4680; chigh=6000; cint=60;
conts = [clow:cint:chigh];
V = [clow:cint*2:chigh];
[c,h]=contour(lat,lon,z,conts,'linewidth',1,'color','k');
clabel(c,h,V);
pcolor(latv,lonv,Vg);
shading interp
colorbar('v');
title('geopotential height and magnitude of geostrophic wind at 500 hPa')
xlabel('longitude'), ylabel('latitude')
end
  3 commentaires
Jonas Damsbo
Jonas Damsbo le 10 Oct 2018
Modifié(e) : Walter Roberson le 10 Oct 2018
It's line
[c,h]=contour(lat,lon,z,conts,'linewidth',1.5,'color','k');
The sizes are:
lat = 9865 x 1
lon = 360 x 1
z = 360 x 181
conts = 1 x 23
Walter Roberson
Walter Roberson le 10 Oct 2018
Your lat variable is about 54 times too large. It would have to be 181 long for that z data.

Connectez-vous pour commenter.

Réponse acceptée

ANKUR KUMAR
ANKUR KUMAR le 10 Oct 2018
Modifié(e) : ANKUR KUMAR le 10 Oct 2018
There are few mistakes I want to highlight. You have used,
contour(lat,lon,z.............
It should be
contour(lon,lat,z................
Moreover make sure that the third argument must be in the dimension of second input X dimension of first input.
Have a look over this example
contour([1:10],[1:15],rand(10,15))
You will get an error
Error using contour (line 48)
The size of X must match the size of Z or
the number of columns of Z.
It should be
contour([1:10],[1:15],rand(10,15)')
Always put lon as the first input and dimension of third should be second X first.

Plus de réponses (0)

Catégories

En savoir plus sur Physics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by