365 day loop for 59 years

2 vues (au cours des 30 derniers jours)
S.S
S.S le 23 Fév 2021
Commenté : Cris LaPierre le 23 Fév 2021
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 commentaires
David Hill
David Hill le 23 Fév 2021
Show us the code you currently have.
S.S
S.S le 23 Fév 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.

Connectez-vous pour commenter.

Réponses (1)

Cris LaPierre
Cris LaPierre le 23 Fév 2021
Modifié(e) : Cris LaPierre le 23 Fév 2021
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 commentaires
S.S
S.S le 23 Fév 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.
Cris LaPierre
Cris LaPierre le 23 Fév 2021
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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by