MATLAB: How to create a grid of half-integer

gridhalf-integerMATLAB

Hello, help me please. To solve problems of the type "boundary layer" need to create a half-integer grid. x=x0+(i+1/2)*dx, i=0,1,2… where dx – step. Example
for i=1:n
for j=1:m
v(i+1/2,j+1)=v(i+1/2,j)+dy*((u(i+1,j)-u(i,j))/dx - (u(i+1,j+1)-u(i,j+1))/dx)/2
end
end
Of course there is an error
Attempted to access u(1.5,2); index must be a positive integer or logical.

Best Answer

Arrays cannot use a non-integer subscript. PERIOD.
Surely you don't expect MATLAB to be able to access element 1.732056253445 of a vector or array? So why would it be able to access element 1.5?
Anyway, an array is just a list of numbers. Those numbers mean what you want them to mean. Numbers (and arrays of them) have no intrinsic meaning otherwise. So nothing stops you from creating an array with 2*n+1 rows in the array.