Storing the result of display function
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (1)
Steven Lord
le 9 Mar 2017
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).'
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!