loop for clock each step is 20 min how to code this
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Sandie Nhatien Vu
il 5 Ago 2016
Commentato: Sandie Nhatien Vu
il 5 Ago 2016
Hi everyone,
i have a problem coding for "clock", that means that the code should only go up to 60 min. and then start over. I know that I have to supply this with an "if-statement, that says if the minutes > 60 then it has to add 1 to the hour and subtract 60 from the minutes.. But how do i code this? How to define i as the hour and j as minutes?
My code so far:
for i = 13:0.2:20;
j = 13.16:0.2:20.16;
fprintf('The Train from London %.2f arrives in Campden at %.2f\n', i, j);
end
Output should look like this:
The Train from london 13.00 arrives in Campden at 13.16
The Train from london 13.20 arrives in Campden at 13.36
The Train from london 13.20 arrives in Campden at 13.56
. . .
The Train from london 20.00 arrives in Campden at 20.16
The train leaves every 20 min and takes 16 min to arrive.
0 Commenti
Risposta accettata
Azzi Abdelmalek
il 5 Ago 2016
Modificato: Azzi Abdelmalek
il 5 Ago 2016
Edit
a=datenum('13:00','HH:MM')
b=datenum('20:00','HH:MM')
jj=a:(1/(24*3)):b
date1=datestr(jj,'HH:MM')
date2=datestr(jj+1/(90),'HH:MM')
for k=1:size(date1,1)
fprintf('The Train from London %s arrives in Campden at %s\n', date1(k,:),date2(k,:));
end
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Fortran with MATLAB in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!