MATLAB: Create one vector from several iterations in for loop

for loopiterationslinspacesplit vectorvector

Hello, I am trying to split a vector into more pieces using a for loop. I have a vector, Lat, which contains latitude points. I wish to add more points in a linear fashion between the existing points in my Lat vector.
In order to do this, I am trying to use a for loop and the linspace operator as follows, splitting each interval in five new pieces.
for i = 1:length(Lat)-1
latitude(i) = linspace(Lat(i),Lat(i+1),5);
end
This does not work. How do I make the for loop understand that I wish to obtain a new vector containing all the points created using the linspace operator?

Best Answer

Try this:
for i = 1:length(Lat)-1
latitude(i,:) = linspace(Lat(i),Lat(i+1),5);
end
latitude = reshape(latitude', 1, []);