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!