Index out of bounds
Show older comments
I'm relatively new to MATLAB and my code is throwing the error "Attempted to access v(2,1); index out of bounds because numel(v)=1. Error in ForcedVortex (line 82) dvdx=(v(ii+1,jj)-v(ii,jj))/(x(ii,jj)-x(ii,jj)); "
This is the code, its to calculate the vorticity at each point and visualise a forced vortex.I thought it was a boundary error problem so replaced introduced a second iteration ii and jj but that didn't solve the problem. Would appreciate any help
%%Read in and set data
dx=1;
dy=1;
k=1;
f=1 %this is used in the angular momentum omega equation. Double check
omega=2*pi*f;
A1=9;
B1=10;
for i=1:A1
for j=1:A1
for ii=1:B1-1
for jj=1:B1-1
x(i,j)=(-5)+(i.*dx);
y(i,j)=(-5)+(j.*dy);
r=sqrt((x(i,j)^2)+(y(i,j)^2));
utheta=omega*r;
ur=0;
sintheta=(y(i,j)/r)
costheta=(x(i,j)/r)
u(i,j)=(-utheta).*(sintheta);
v(i,j)=(utheta).*(costheta);
dvdx=(v(ii+1,jj)-v(ii,jj))/(x(ii+1,jj)-x(ii,jj));
dudy=(u(ii,jj+1)-u(ii,jj))/(y(ii,jj+1)-y(ii,jj));
VorticityPoint=(dudy-dvdx)*k;
Vorticity(i,j)=VorticityPoint
end
end
end
end
imagesc(Vorticity),colorbar
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!