Create one vector from several iterations in for loop

1 回表示 (過去 30 日間)
Anna
Anna 2017 年 4 月 11 日
コメント済み: Star Strider 2017 年 4 月 13 日
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?

採用された回答

Star Strider
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, []);
  6 件のコメント
Anna
Anna 2017 年 4 月 12 日
This works great! Thank you so much for you help!
Star Strider
Star Strider 2017 年 4 月 13 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (1 件)

Andrei Bobrov
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)];

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by