Interpolate multiple data for a plot

1 visualización (últimos 30 días)
Madlab
Madlab el 17 de Oct. de 2018
Comentada: jonas el 18 de Oct. de 2018
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 comentarios
Madlab
Madlab el 17 de Oct. de 2018
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 el 17 de Oct. de 2018
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.

Iniciar sesión para comentar.

Respuesta aceptada

jonas
jonas el 17 de Oct. de 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 comentarios
Madlab
Madlab el 18 de Oct. de 2018
Editada: Madlab el 18 de Oct. de 2018
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 el 18 de Oct. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by