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).
2 次查看(过去 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')
0 个评论
回答(1 个)
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);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Stress and Strain 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!