Hi there,
This is a beginner question, I'm very new to MATLAB.
I have 59 years worth of data in one column starting in October. There is 1 data point for every day in the year. I would like to create a loop which produces a graph for the data in every year for each of the 59 years.
Thanks,
SS.

4 comentarios

Mathieu NOE
Mathieu NOE el 23 de Feb. de 2021
hello
maybe you should share the data file to let us help you
Cris LaPierre
Cris LaPierre el 23 de Feb. de 2021
Don't forget - every 4 years there are 366 days.
David Hill
David Hill el 23 de Feb. de 2021
Show us the code you currently have.
S.S
S.S el 23 de Feb. de 2021
Hi there,
Thanks for taking a look at my question. I have attached the data file, which is in excel format.
Kind regards,
SS.

Iniciar sesión para comentar.

Respuestas (1)

Cris LaPierre
Cris LaPierre el 23 de Feb. de 2021
Editada: Cris LaPierre el 23 de Feb. de 2021

0 votos

Make sure your dates are datetimes. Then you can take advantage of the dates and time functions.
Here's a rought outline.
startY = min(year(data.Var1));
endY = max(year(data.Var1));
for y = startY:endY
ind = year(data.Var1)==y;
plot(day(data.Var1(ind),'dayofyear'),data.Var2(ind))
hold on
end
hold off

3 comentarios

Cris LaPierre
Cris LaPierre el 23 de Feb. de 2021
Editada: Cris LaPierre el 23 de Feb. de 2021
This solution will work for your data. You just have to load your spreadsheet into MATLAB. I'd use readtable.
data = readtable("data .xlsx",'Sheet','Sheet2')
The variable data is a table data type. See this page on how to access data in a table.
S.S
S.S el 23 de Feb. de 2021
Hi Cris,
Thanks for answering my question. I imported the data from matlab and then converted the date formats from excel to matlab so my codes reads like this at the beggining:
X = data(:,1);
Y = data(:,2);
t = datetime(X,'ConvertFrom','excel')
So, now I have to columns one t with the dates that I would like to use as the X axis and column two (Y) which I'd like to plot on the Y axis
I'm not a bit unsure, how to translate these into the code above. Sorry I'm a big biggner here!
Kind regards,
SS.
Just combine the two. That's all you need. The readtable function will automatically handle the date for you. This was run in R2020b.
data = readtable("SSdata .xlsx",'Sheet','Sheet2') % I saved your file with this name
data = 21549x2 table
Var1 Var2 ___________ ____ 01-Oct-1960 8.07 02-Oct-1960 59.8 03-Oct-1960 53.2 04-Oct-1960 23.3 05-Oct-1960 19.1 06-Oct-1960 15.4 07-Oct-1960 11.6 08-Oct-1960 11.6 09-Oct-1960 9.46 10-Oct-1960 8.81 11-Oct-1960 7.76 12-Oct-1960 13.3 13-Oct-1960 8.04 14-Oct-1960 8.75 15-Oct-1960 6.88 16-Oct-1960 6.23
startY = min(year(data.Var1));
endY = max(year(data.Var1));
for y = startY:endY
ind = year(data.Var1)==y;
plot(day(data.Var1(ind),'dayofyear'),data.Var2(ind))
hold on
end
hold off

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

S.S
el 23 de Feb. de 2021

Comentada:

el 23 de Feb. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by