Overlaying time series data

8 views (last 30 days)
Miriam Daughtery
Miriam Daughtery on 20 Dec 2019
Answered: Star Strider on 20 Dec 2019
I am trying to overlay the years of data on top of one another rather than have them in order so I can compare them in better detail. Anyone have any idea?
years.jpg
Here are my 4 scripts I have used to plot this:
To process the data:
function data=processfile(filename)
% function to load data from COPEPOD
% input is the filename of the data file
% output is the Year/Month and Adundance from the data file
% tmp=tempory l=line
data.filename=filename; %each time i look at output data with contain name of data file it loaded data from
fid=fopen(filename); %opens up data file
%Skips headerlines
for I=1:18 %loop to repeat until the desired line is reached e.g. 18 is when the text that i am interested in starts
tmpl=fgetl(fid); %fgetl=function get line %fid=file identifier %tmpl=asssigned name of variable to capture each line
end
%disp(tmpl);
J=1;
while ischar(tmpl)
% 21 strings
tmp=textscan(tmpl,'%s',32,'Delimiter',','); %takes the input of the loop line with format spec= what we are going to break it into e.g. %s = strings
data.date(J)=datenum( str2num( cell2mat(tmp{1}(2))), str2num( cell2mat(tmp{1}(3))),str2num( cell2mat(tmp{1}(4))))+str2num( cell2mat(tmp{1}(5)))/24; %year, month, day, time /fraction of day adding onto date
data.Plankton=str2num(cell2mat(tmp{1}(22))); %plankton amount %datestr(data1994_april.d) to display date properly
tmpPlankton=str2num(cell2mat(tmp{1}(22)));
if isempty(tmpPlankton)
tmpPlankton=NaN;
end
data.Plankton(J)=tmpPlankton;
tmpl=fgetl(fid);
J=J+1;
end
%data.datetime(J)=datenum( cell2mat(tmp{1}) );
%
% data.CO2(J)=tmp{2};
%
%
% end
%
fclose(fid); %closes file
%calculate mean and std
data.date=mean(data.date);
data.stdPlankton=std(data.Plankton)
data.Plankton=mean(data.Plankton);
To load the data:
function output = loadalldata (foldername)
%d=dir('*.csv');
d = dir ([foldername filesep '*.csv']);
data.date=[];
data.Plankton=[];
data.stdPlankton=[];
for I=1:length(d)
tmp=processfile([foldername filesep d(I).name]);
data.date=[data.date tmp.date];
data.Plankton=[data.Plankton tmp.Plankton];
data.stdPlankton=[data.stdPlankton tmp.stdPlankton];
end
output.data.date=data.date;
output.data.Plankton=data.Plankton;
output.data.stdPlankton=data.stdPlankton;
To plot the data:
cm = colormap(lines(12));
figure (1)
%subplot (3,1,1)
%clears figure after use so they don't overlay
plot(data1995.data.date,data1995.data.Plankton,'-','Color',cm(1,:))
hold on
plot(data1996.data.date,data1996.data.Plankton,'-','Color',cm(2,:))
plot(data1997.data.date,data1997.data.Plankton,'-','Color',cm(3,:))
plot(data1998.data.date,data1998.data.Plankton,'-','Color',cm(4,:))
plot(data1999.data.date,data1999.data.Plankton,'-','Color',cm(5,:))
plot(data2000.data.date,data2000.data.Plankton,'-','Color',cm(6,:))
plot(data2001.data.date,data2001.data.Plankton,'-','Color',cm(7,:))
plot(data2002.data.date,data2002.data.Plankton,'-','Color',cm(8,:))
plot(data2003.data.date,data2003.data.Plankton,'-','Color',cm(9,:))
plot(data2004.data.date,data2004.data.Plankton,'-','Color',cm(10,:))
plot(data2005.data.date,data2005.data.Plankton,'-','Color',cm(11,:))
plot(data2006.data.date,data2006.data.Plankton,'-','Color',cm(12,:))
errorbar(data.date,data.Plankton,data.stdPlankton,'.b-','MarkerEdgeColor','r','MarkerSize',17,'LineWidth', 1.5)
xlabel('Day Of Year')
ylabel ('SST (^oC)')
%title ('SST at L4 2009-2016', 'fontsize', 16)
legend ('1995','1996','1997','1998','1999','2000','2001','2002', '2003', '2004', '2005', '2006')
Thanks you.

Answers (1)

Star Strider
Star Strider on 20 Dec 2019
You are creating an ensemble. This is frequently done in order to take the mean (ensemble average) of data at particular time points over a number of records. See: cutting up the signal into repeating parts for one example.

Categories

Find more on Graphics Object Properties 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!