Having trouble with quiver3() Sizing issues

16 views (last 30 days)
Shane
Shane on 16 Jun 2014
Answered: Star Strider on 16 Jun 2014
The error shows:
if true
clear all
nx=100; %Number of steps in space(x)
ny=100; %Number of steps in space(y)
nz=70;
tf=60; %Final time
dt=1e-2; %Width of time step
nt=ceil(tf/dt); %Number of time steps
dt=tf/nt; %Corrected time step
H=.2; %Height of the container
L=.82; %Length of the container
W=.5;
dx=L/(nx-1); %Width of space step(x)
dy=H/(ny-1); %Width of space step(y)
dz=W/(nz-1);
x=0:dx:L; %Range of x(0,2) and specifying grid points
y=0:dy:H; %Range of y(0,5) and specifying grid points
z=0:dz:W;
TN=25; %Top wall temperature
TS=70; %Bottom wall temperature
u=zeros(nx+1,ny); %Preallocating u
v=zeros(nx,ny+1); %Preallocating v
w=zeros(nx,nz+1);
p=zeros(nx,ny); %Preallocating p
S=zeros(nx,ny); %Preallocating S
uplot=zeros(nx,ny); %Preallocating uplot
vplot=zeros(nx,ny); %Preallocating vplot
To=min(TS,TN); %Initial temperature
T=To*ones(nx,ny); %Preallocating T (Initial conditions)
Re=1e2; %Reynolds number
Pr=7; %Prandtl number
Pe=Re*Pr; %Peclet number
Ra=1e2; %Rayleigh number
Gr=Ra/Pr; %Grashoff number
Tstar=T;
ustar=u; uhalf=u; uconv=u;
vstar=v; vhalf=v; vconv=v;
TnE=0; TnW=0;
UN=0; VN=0;
US=0; VS=0;
UE=0; VW=0;
UW=0; VE=0;
for it=0:nt
uplot(1:nx,1:ny)=0.5*(u(1:nx,1:ny)+u(2:nx+1,1:ny));
vplot(1:nx,1:ny)=0.5*(v(1:nx,1:ny)+v(1:nx,2:ny+1));
wplot(1:nx,1:nz)=0.5*(w(1:nx,1:nz)+w(1:nx,2:nz+1));
if(rem(it,30)==0)
quiver3(x,y,z,uplot',vplot',wplot',5,'k');
axis equal
axis([0 L 0 H])
hold on
pcolor(x,y,z,T');
colormap(jet)
colorbar
shading interp
axis equal
axis([0 L 0 H])
title({['Rayleigh-Benard Convection with Pe = ',num2str(Pe),' and Gr = ',num2str(Gr)];['time(\itt) = ',num2str(dt*it)]})
xlabel('Spatial co-ordinate (x) \rightarrow')
ylabel('Spatial co-ordinate (y) \rightarrow')
zlabel('Spatial co-ordinate (z) \rightarrow')
drawnow;
hold off
end
Error using quiver3 (line 57) Z and U must be the same size.
Error in Benard_plot (line 47) quiver3(x,y,z,uplot',vplot',wplot',5,'k');

Answers (2)

Star Strider
Star Strider on 16 Jun 2014
I’m not sure what you’re doing in your code, but according to the documentation for quiver3:
  • quiver3(x,y,z,u,v,w) plots vectors with directions determined by components (u,v,w) at points determined by (x,y,z) . The matrices x,y,z,u,v,w must all be the same size and contain the corresponding position and vector components.
Your x, y, z are vectors, and uplot, vplot, wplot are (appropriately) matrices.

Chad Greene
Chad Greene on 16 Jun 2014
From the documentation for quiver3, "The matrices X,Y,Z,U,V,W must all be the same size..." In your code, x and y are 1x100, z is 1x70, uplot and vplot are 100x100, and wplot is 100x70. The quiver3 function wants vector components u,v, and w for each point given by x, y, and z.
  1 Comment
Chad Greene
Chad Greene on 16 Jun 2014
On a side note, I'd make a habit of declaring more colors in your colormap for a smoother gradient in your colorbar. For example, colormap(jet(256)).

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!