## How do I create a repeating number series?

### Robert Earles (view profile)

on 10 Apr 2019
Latest activity Commented on by Robert Earles

on 10 Apr 2019

### John D'Errico (view profile)

Hi guys,
I am doing some work with data taken every 30 minutes over a period of 5 years. For one of the equations I need to use in the programme, it requires a term called 'h', which refers to the midpoint of the calculation period, with units of hours (written as a decimal) of the day. For instance, for the midpoint between 14:00 and 14:30, h=14.25, and for the midpoint of 14:30 and 15:00, h=14.75.
My problem is generating this term h to use in equations.
My total value for the amount of terms in this dataset is a value around 87,000.
So far I have made this:
h=0.25;
n=49;
for i=1:n
h(i+1)=h(i)+0.5
end
which generates:
Columns 1 through 11
0.2500 0.7500 1.2500 1.7500 2.2500 2.7500 3.2500 3.7500 4.2500 4.7500 5.2500
Columns 12 through 22
5.7500 6.2500 6.7500 7.2500 7.7500 8.2500 8.7500 9.2500 9.7500 10.2500 10.7500
Columns 23 through 33
11.2500 11.7500 12.2500 12.7500 13.2500 13.7500 14.2500 14.7500 15.2500 15.7500 16.2500
Columns 34 through 44
16.7500 17.2500 17.7500 18.2500 18.7500 19.2500 19.7500 20.2500 20.7500 21.2500 21.7500
Columns 45 through 50
22.2500 22.7500 23.2500 23.7500 24.2500 24.7500
This is what I want, however this only represents one day. I want to make this series repeat so after 24.75 of one day, the sequence resets to 0.25 for the new day and this sequence repeats itself for every day in the dataset, which is all 87,000 data points. How would I do this?
Thanks, Rob

### John D'Errico (view profile)

on 10 Apr 2019
Edited by John D'Errico

### John D'Errico (view profile)

on 10 Apr 2019

LEARN TO USE MATLAB.
0.25:.5:25
ans =
Columns 1 through 11
0.25 0.75 1.25 1.75 2.25 2.75 3.25 3.75 4.25 4.75 5.25
Columns 12 through 22
5.75 6.25 6.75 7.25 7.75 8.25 8.75 9.25 9.75 10.25 10.75
Columns 23 through 33
11.25 11.75 12.25 12.75 13.25 13.75 14.25 14.75 15.25 15.75 16.25
Columns 34 through 44
16.75 17.25 17.75 18.25 18.75 19.25 19.75 20.25 20.75 21.25 21.75
Columns 45 through 50
22.25 22.75 23.25 23.75 24.25 24.75
The point is, the colon operator would be nearly the first thing you would learn were you to read the getting started tutorial in MATLAB. Don't skip reading the manual.
Next, you want to repeat this. For how many days? You can count how many you need for 5 years. The simplest way to repeat a vector is to use repmat. So you might end up with this:
h = repmat(0.25:.5:25,1,5*365);
Again, repmat is one of those things you will see in the basic getting started tutorials. READ THEM, as they were put there for you to use and learn from. Otherwise, you will be asking dozens of basic questions you would have learned the answer to in just a few minutes of reading.

Robert Earles

### Robert Earles (view profile)

on 10 Apr 2019
Thank you very much.
Yeah I should read the manual. Basically I’m at uni and I was put on a course by them which I’m assuming is different to the manual. I have read about colon operator and I understand how that works as well as some other basic functions, however for some reason I just thought a for loop would be the way to go. But yes using colon operator makes a lot more sense.
With regards to repmat, I didn’t come across that in my course so I will definitely check back to the manual to avoid future simple issues.
Thanks again!