loop for clock each step is 20 min how to code this
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Azzi Abdelmalek
2016-8-5
编辑:Azzi Abdelmalek
2016-8-5
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Fortran with MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!