Storing the result of display function

if true
for i = 1749:2016
n = 0 ;
while n < 12
mescortado = i + n/12;
n = n+1;
disp(mescortado)
end
end
end
So my idea is making an array with the numbers between 1749 and 2016, with 12 steps per integer, like it was the months of the year. The script above kinda does what i want like this:
if true
1749
1749.08333333333
1749.16666666667
1749.25000000000
1749.33333333333
1749.41666666667
1749.50000000000
1749.58333333333
1749.66666666667
1749.75000000000
1749.83333333333
1749.91666666667
1750
end
The problem is that I'm using the display function , which doesn't let me store or work with the values like an array and only shows the answer in console. I also tried to make some for-loops that made an array, but it just made a long array with only the last value (2016.916). Is there a way to make the display result as an array, or better, a correct use of loops for making an array with the years? Thank you in advance

 Accepted Answer

result = 1749:1/12:2016;
should give the same result in an array.

More Answers (1)

If you want to represent these numbers as actual dates, say the first of each month, use datetime objects with a calendarDuration object created by calmonths for monthly spacing.
startDate = datetime(1749, 1, 1);
endDate = datetime(2016, 1, 1);
x = startDate:calmonths(1):endDate;
firstTwentyMonths = x(1:20).'

Categories

Find more on Loops and Conditional Statements 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!