Plotting Wind Vectors at Various Atmospheric Pressure Levels...
18 次查看(过去 30 天)
显示 更早的评论
Good morning!
I'm trying to plot wind vectors using MATLAB's quiver function. While I can successfully plot a 2-d wind vector using U and V components at one (1) atmospheric pressure level, I would like to create a "wind profile" where I show the direction of wind across 21 atmospheric pressure levels. I researched a bit and was happy to find the quiver3 function, however, I have run into some questions regarding the implementation of the function's components.
Both my U and V wind components are of size 180 x 360 x 21, representing latitude, longitude, and atmospheric pressure level, respectively. While I think my "u_wind" and "v_wind" variables are ready for use in the function, I don't know what to use to match the Z component within the function. For now, I've tried to substitude the "w" component (this matches the Z component) with "u_wind," but I know this is incorrect - I receive an error message which reads: Z and U must be the same size. Any suggestions on how I can fix this code or how I could come up with an appropriate "w" component? Any feedback would be greatly appreciated.
Thanks again for your time and consideration!
myfile = ('wind_file_Np.19800805.nc4.nc4')
ncdisp(myfile)
u_wind = ncread(myfile, 'U', [1, 1, 1], [inf, inf, 21]);
v_wind = ncread(myfile, 'V', [1, 1, 1], [inf, inf, 21]);
size(u_wind) ***180 x 360 x 21
size(v_wind) ***180 x 360 x 21
X = -180:1:180
Y = -90:0.5:90
Z = 1:1:21
quiver3(X, Y, Z, u_wind, v_wind, u_wind) ***please help here
xlim([-180 180])
ylim([-90 90])
0 个评论
回答(1 个)
Sulaymon Eshkabilov
2021-6-19
You habe the size related issues in your code:
X = linspace(-180,180, 360); % Size problem fixed
Y = linspace(-90,90, 180); % Size problem fixed
[XX, YY]=meshgrid(X, Y); % Meshgrid is necessary
Z = meshgrid(linspace(1,21, numel(X)), linspace(1,21, numel(Y))); % Meshgrid and Size issues are resolved
quiver3(X, Y, Z, u_wind(:,:,1)', v_wind(:,:,1)', u_wind(:,:,1)') % Data layer by layer has to be chosen
...
% Similarly, you can add plot (or add) other layers: u_wind(:,:, 2), ...
% u_wind(:,:,3), etc.
1 个评论
Gethin Manuel
2021-10-1
Hi Michelle and Sulaymon,
Did you get this working for all of the atmospheric pressure levels? I am doing the same thing but just plotting against altitude, one slice at a time. I'm trying to overlay a quiver plot on to the slice to show vector wind speed as a colourmap. However, I can get the slice plot to the altitude that I'm observing but the quiver plot stays at zero altitude, even when I use quiver3 and give it the same meshgrid used in the slice plot. I have no w components in my wind data, just u and v, so I set the w component to zero, but it still stays at the base of the plot. Any ideas how I can raise the quiver plot to be at the same altitude as the slice? I've tried just quiver, and quiver 3 separately.
Best
Gethin
See screenshots
sorry for the long message.
Code:
%% 3D slice
figure(2)
% Create a height layer
[A,B,C] = meshgrid(x,y,0:h(height_bin));
xslice = [];
yslice = [];
zslice = h(height_bin);
V = C.*Vect;
slice(A,B,C,V,xslice,yslice,zslice)
zlim ([0 zslice])
colormap jet
cc = colorbar
cc.Label.String = 'Wind Speed (mph)';
hold on
quiver(X,Y,uAll(r1:r2,:),vAll(r1:r2,:),'k')
ylabel('Latitude'); xlabel('Longitude'); zlabel('Altitude(m)')
%% 3d Quiver
% give the X,Y quiver components the same as U and V
% Set the Z quiver (W) components to 0
figure(3)
% Re use A, B and C for the meshgrid components
% Convert u, v and w components from 2D into 3D matrices
u3 = uAll(r1:r2,:);
u3(:,:,11) = zeros(size(u3));
v3 = vAll(r1:r2,:);
v3(:,:,11) = zeros(size(v3));
w3 = zeros(size(u3));
quiver3(A,B,C,u3,v3,w3)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Vector Fields 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!