Create one vector from several iterations in for loop
Show older comments
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?
Accepted Answer
More Answers (1)
Andrei Bobrov
on 12 Apr 2017
Edited: Andrei Bobrov
on 12 Apr 2017
n = 5;
Latitude = [Lat(1);reshape(reshape(Lat(1:end-1),1,[])...
+ cumsum(ones(n,1)* diff(Lat(:)')/n),[],1)];
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!