MATLAB: Creating a matrix using arrays

arrayfor loopmatrix

I am trying to create a matrix where each row is xstart:inc:xend, where the value begins at xstart and is increased by xinc to xend. so, a 30 x 37 matrix.
I am using the following:
XL = 96.5;
dx = 0.423;
n = 1:30;
xstart = 0+n*dx;
xend = XL-n*dx;
xinc = xend/37;
what I have so far,
xr = zeros(30,37);
for i = 1:length(n)
xr(i,:) = xstart(1,i):xinc(1,i):xend(1,i);
end
I have tried different variations of the left side, xr(i), but I am still getting an error that states, "Unable to perform assignment because the indices on the left side are not compatible with the size of the right side."
I computed the following, but I was wondering if I have to do this 30 times.
xr1 = xstart(1,1):xinc(1,1):xend(1,1);
xr2 = xstart(1,2):xinc(1,2):xend(1,2);
xr3 = xstart(1,3):xinc(1,3):xend(1,3);

Best Answer

How about the following?
XL = 96.5;
dx = 0.423;
n = 1:30;
xstart = 0+n*dx;
xend = XL-n*dx;
xr = zeros(30,37);
for kk = 1:length(n)
xr(kk,:) = linspace(xstart(kk),xend(kk),37);
end
or
xr = arrayfun(@(x,y) linspace(x,y,37),xstart',xend','UniformOutput',false);
xr = cell2mat(xr);