MATLAB: Maximum variable size allowed by the program is exceeded

error using ones maximum variable size allowed by the program

PLz help me
This is the code
alps=17; %slope angle
dz=200; %depth of water table from the suface
dlz=400; % toltal depth of slope
fi=25; %friction angle
C=0.4; %4 kpa=0.4 N/cm^2
gsat=0.21; %21 kN/m^3
gw=0.098; %9.81 Kn/m^3
Dzero=4; %0.0004m^2/s
ksat=1e-3; %e-5 m/s
iz=2e-4; %iz=7.2 mm/h= 2e-4 cm/s
deltat=10; %time step
deltaz=0.8; %space step
T=12*60*60; %time duration of rainfall= 12h to seconds
e=(deltat/deltaz^2)*Dzero*cos(17*pi/180)*cos(17*pi/180);
n=500; %time step, based on T
%Setup sparse matrix
b= sparse(1:n,1:n,-116.314,n,n); % element b... 1...n
c= sparse(1:n-1,2:n,e,n,n); % element c...
a= sparse(2:n,1:n-1,-e,n,n); % element a... 2...n-1
c(1)=114.314; a(1)=0; a(n)=114.314; %Boundary condition
A= a+b+c;
l=e*ones(1:n); m=112.314*ones(1:n); u=e*ones(1:n);
and This is the error below, please tell me why this error appears and how to solve. My system is 64 bit and 6gb ram and processor speed is 2.5 Ghz Error using ones Maximum variable size allowed by the program is exceeded.
Error in hillslopesparse (line 30)
l=e*ones(1:n); m=112.314*ones(1:n); u=e*ones(1:n);

Best Answer

ones(1:n) tries to create a n-dimensional monster. Try
>> ones(1:3)
ans(:,:,1) =
1 1
ans(:,:,2) =
1 1
ans(:,:,3) =
1 1
I assume that you want to create a vector. Try
m = ones(1,n);
k = ones(n,1);
whos m k
which returns
Name Size Bytes Class Attributes
k 500x1 4000 double
m 1x500 4000 double