Matlab: out of bounds.

  • MATLAB
  • Thread starter MaxManus
  • Start date
  • #1
277
0

Main Question or Discussion Point

Hey, I have defined
Code:
pu = zeros(nx,ny,N);
pv = zeros(nx,ny,N);
pu(:,ny,:) = 1;
and written the loop:
line 38-40
Code:
 for i = 2:(nx-1);
        for i = 2:(ny-1);
            ps(i,j) = p(i,j,n) - a1*(pu(i+1,j,n) - pu(i,j,n)) -a2*(pv(i,j+1,n) - pv(i,j,n));
and I get the error
??? Attempted to access pv(2,11,1); index out of bounds because size(pv)=[10,10,10].

Error in ==> fluidmekanikk at 40
ps(i,j) = p(i,j,n) - a1*(pu(i+1,j,n) - pu(i,j,n)) -a2*(pv(i,j+1,n) - pv(i,j,n));
Could someone help me with the error?
 

Answers and Replies

  • #2
Hurkyl
Staff Emeritus
Science Advisor
Gold Member
14,916
17
Well, obviously, you tried to access p(2,11,1) which does not exist.

Looking at the indexes, it was probably pv(i,j+1,n), since that goes highest int he middle term.

Now... what range does j iterate over?
 
  • #3
277
0
Well, obviously, you tried to access p(2,11,1) which does not exist.

Looking at the indexes, it was probably pv(i,j+1,n), since that goes highest int he middle term.

Now... what range does j iterate over?
Thanks for fast reply and solution.
The code
Code:
for i = 2:(nx-1);
        for i = 2:(ny-1);
was supposed to be
Code:
for i = 2:(nx-1);
        for j = 2:(ny-1);
and I had used the j as variable earlier.
 
Last edited:

Related Threads for: Matlab: out of bounds.

Replies
14
Views
71K
  • Last Post
Replies
1
Views
3K
Replies
0
Views
3K
Replies
2
Views
2K
Replies
0
Views
3K
Replies
2
Views
4K
Replies
6
Views
16K
Replies
1
Views
43K
Top