Interpolate multiple data for a plot
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
jonas
on 17 Oct 2018
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 Comments
jonas
on 18 Oct 2018
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.
More Answers (0)
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!