Code returns, "Error using quiver3 (line 44) V and W must be the same size." How to fix this? The variables are the same size(1x25 double).

3 次查看(过去 30 天)
%% Program to plot Ekman spiral
%% Input section
clear all; close all;
i=sqrt(-1) % To make sure i is the complex i
h=120; % Water depth
nut=.02; % (constant) turbulence viscosity
phi=51; % Latitude (deg.)
rho=1000; % Water density
tauwx=0; % Wind shear stress x-direction
tauwy=1; % Wind shear stress y-direction
tau=tauwx+tauwy*i; % Shear stress vector
f=2*7.27e-5*sin(phi*pi/180); % Coriolis coefficient
dek=sqrt(2*nut/f) % Ekman depth
dz=5; % Vertical step size
zek=[-h:dz:0]; % Vertical coordinate
%% Define some additional matrices for plotting purposes
xek=zeros(size(zek));
yek=zeros(size(zek));
taux=zeros(size(zek));
tauy=zeros(size(zek));
taux(end)=tauwx;
tauy(end)=tauwy;
%% Solution of Ekman spiral
s=tau*dek/rho/(1+i)/nut*exp((1+i)/dek*zek);
uek=real(s);
vek=imag(s);
%% Plot results
figure(1);
quiver3(xek,yek,zek,uek,vek,0,'linewidth',2);
hold on
quiver3(xek,yek,zek,taux,tauy,0,'r','linewidth',2);
title('Ekman spiral')
xlabel('u');ylabel('v');
zlabel('z')
print('-dpng','ekman.png')
print('-depsc','ekman.eps')

回答(1 个)

Mischa Kim
Mischa Kim 2017-10-26
Aamna, based on your information I am not clear exactly what you want to do. However, the input arguments for coordinates and vectors in quiver3 all must be the same size. You can use meshgrid to achieve that:
%%Solution of Ekman spiral
[XEK,YEK,ZEK] = meshgrid(xek,yek,zek);
s = tau*dek/rho/(1+i)/nut*exp((1+i)/dek*ZEK);
uek = real(s);
vek = imag(s);
%%Plot results
figure(1);
quiver3(XEK,YEK,YEK,uek,vek,zeros(size(uek)),'linewidth',2);
Check out the doc for more information.

类别

Help CenterFile Exchange 中查找有关 Stress and Strain 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by