Create one vector from several iterations in for loop
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Star Strider
2017-4-11
Try this:
for i = 1:length(Lat)-1
latitude(i,:) = linspace(Lat(i),Lat(i+1),5);
end
latitude = reshape(latitude', 1, []);
更多回答(1 个)
Andrei Bobrov
2017-4-12
编辑:Andrei Bobrov
2017-4-12
n = 5;
Latitude = [Lat(1);reshape(reshape(Lat(1:end-1),1,[])...
+ cumsum(ones(n,1)* diff(Lat(:)')/n),[],1)];
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!