Interpolate multiple data for a plot

1 回表示 (過去 30 日間)
Madlab
Madlab 2018 年 10 月 17 日
コメント済み: jonas 2018 年 10 月 18 日
I am having trouble interpolating data. I don't quite know what variables to insert into interp1. I need to plot sea against temperature after interpolating as the time for sea and time for weather is different. Any tips?
for k=1:7
figure
w{k} = interp1(timeweather{k},avgtemp{k},sealevel{k},'linear');
plot(timeweather{k},avgtemp{k},'-',5,w{k},'*')
plot(timeweather{k},avgtemp{k},'r')
hold on
plot(timesea{k},sealevel{k},'c')
end
  3 件のコメント
Madlab
Madlab 2018 年 10 月 17 日
The time format is in decimal years for both timeweather and timesea.
Yes, each corresponds to a different location. For location X, the sealevel is sealevel{1} for timesea{1} while the temperature is avgtemp{1} for timeweather{1}. I need to interpolate to see how the temperature and sealevel are related.
Likewise, for location Y, the sealevel is sealevel{2} for timesea{2} while the temperature is avgtemp{2} for timeweather{2}. I need to interpolate to see how the temperature and sealevel are related.
And this continues for the different locations...
Madlab
Madlab 2018 年 10 月 17 日
Sorry, but I do not understand what you mean by "use a timetable and synchronize." Isn't interp1 supposed to help me synchronise the data? I am very confused.

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

採用された回答

jonas
jonas 2018 年 10 月 17 日
Normally I'm not a big fan of fraction years, but here we go:
% Common time vector
tc = 1850:.1:2020;
% interpolate
out.sealevel = cellfun(@(x,y)interp1(x,y,tc),timesea,sealevel,'uniformoutput',false)
out.temp = cellfun(@(x,y)interp1(x,y,tc),timeweather,avgtemp,'uniformoutput',false)
all time-series stored in the struct out can be plotted against the common time vector tc.
  2 件のコメント
Madlab
Madlab 2018 年 10 月 18 日
編集済み: Madlab 2018 年 10 月 18 日
Hey Jonas, thank you for the input. I would like to ask though, what is the use of x and y? I know that cellfun applies a function to each cell of a cell array, which in this case is timesea,sealevel.
So this interpolates all the data for each respective cell with the help of cellfun. May I also ask what is the use of false behind uniformoutput?
jonas
jonas 2018 年 10 月 18 日
This is the function
@(x,y)interp1(x,y,tc)
x and y are the variables. Cellfun applies this function to each cell in the inputs that come as the 2nd and 3rd arguments in this case.
...'uniformoutput',false
just means that the output cells does not have to be of the same size. It may not be necessary in this case.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by