Time Series analysis problems with date

Hi all-and a happy new year (lets hope its better than the last one......)
My query concerns time series.
I have a dataset which consists of 7 seperate excel files, first column is date and second column is a scalar number.
The date is a period of 8 months, jan-aug for 10 years (repeated in each excel file).
I have plotted the first file and the first 8 months plot fine for the ten year period, however, the sep-dec period is also plotted which shows no data, therefore there is a straight line until the next year starts on the graph.
I have used the code
= datevec(cam{:,1}); and also tried
= datenum (cam{:,1});
both do not work!!
So my question is how do I plot the data for just the dates shown which Jan 1st-Aug 31st 2010-2020?
Im fairly new to all this, I have tried using the mathworks help section and tried several other pieces of code, but I get the dreaded red writing, I apologise if this is a billy basic question!
many thanks in advance
Mike

4 comentarios

Eric Sofen
Eric Sofen el 6 de En. de 2021
It will be helpful to see some sample data and more of the code you've tried to write for context. I'm not sure what cam{:,1} refers to.
To get things started, I'd encourage you to use the datetime type rather than the older datenum/datevec.
Hey Eric,
sorry for the delay in response!
Column 1 are the dates and column 2 are the values I am interested in.
% this is how I load the data
infmt = 'dd-MM-yyyy';
data_all = datetime(testData{:,1}, 'InputFormat',infmt);
gas = testData{:,2};
I now tried to replace the values from Sep-Dec with NaN, but this tricks Matlab into thinking that these values are equal to dates where there are no measurements (eg system failure). So I can't do interpolation etc.
I then tried to concatenate (see below), but this somehow looses all the date information.
n2010 = find(data_all>='2010-01-01' & data_all<='2010-08-31');
n2011 = find(data_all>='2011-01-01' & data_all<='2011-08-31');
C1=cat(1,n2010,n2011);
Is there a way to only select/plot Jan-Aug over a set period of years?
Thank you!
Adam Danz
Adam Danz el 17 de En. de 2021
Is the goal to remove the straight line from the data while maintaining the sept-dec dates along the x axis? Or is the goal to remove the gap completly and jump from Aug to Jan along the x axis?
mike
mike el 17 de En. de 2021
Hi Adam,
Ideally to remove the lines and the gaps from the x axis so that I can them smooth and detrend.
Cheers

Iniciar sesión para comentar.

Respuestas (1)

Biral Pradhan
Biral Pradhan el 25 de En. de 2022

0 votos

I understand, you want to remove the straight line as well as x-axis labels corresponding to those 4 months (Sep-Dec) for each year. I assume, you plan on interpolating the data for these 4 months later. While plotting monthly data using datetime values from different tables (as in your case), the axis spacing is determined uniformly, so you get labels separated by 1 calendar month.
I do not think it is possible to abruptly change the spacing from 1 calender month to 4 abruptly. A workaround would be to use a timetable and resample your data.

Categorías

Productos

Preguntada:

el 4 de En. de 2021

Respondida:

el 25 de En. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by