Linearly "interpolate" a 1-dimensional vector

1 回表示 (過去 30 日間)
wy6622
wy6622 2019 年 2 月 13 日
コメント済み: Jan 2019 年 2 月 14 日
Hello,
I have a vector of annual population figures for a number of years. I'd like to assume a linear growth and obtain the implied weekly figures. Is there an easier way than using interp1 and having to create an x grid of the years [1 2 3...] and the query points [1/52 2/52....1, 1 1/52, 1 2/52....]? Something like
[pop,txt,raw]= xlsread('annual population.xlsx');
pop=pop(:,1:2);
weekpop=[];
for i=1:21 %1997-2017 21 years
weekpop=[weekpop; linspace(pop(23-i,2),pop(23-1-i,2),52)'];
end
sort of works but doing linspace on a vector of values duplicates the end points (the pop in the 52nd week of year t-1 is the same as pop in week 1 of year t)
Thank you!

採用された回答

Jan
Jan 2019 年 2 月 13 日
What's wrong with interp1?
pops = flipud(pop(:,2));
n = numel(pops);
weekpop = interp1(1:n, pops, linspace(1, n, (n-1) * 52))
  2 件のコメント
wy6622
wy6622 2019 年 2 月 13 日
I wasn't able to come up with an elegant way to write the query points like your "linspace(1, n, (n-1) * 52)". Thank you!
Jan
Jan 2019 年 2 月 14 日
You are welcome.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by