MATLAB Answers

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).

조회 수: 16(최근 30일)
Aamna  Jangda
Aamna Jangda 25 Oct 2017
답변: Mischa Kim 26 Oct 2017
%% 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

로그인 to comment.

답변(1개)

Mischa Kim
Mischa Kim 26 Oct 2017
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.

  댓글 수: 0

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by