Interpolate multiple data for a plot
1 次查看(过去 30 天)
显示 更早的评论
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
采纳的回答
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 个评论
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 Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!