loop for clock in MATLAB
2 次查看(过去 30 天)
显示 更早的评论
hi all, I wanna do loop for an output to be like this
12:00
12:15
12:30
12:45
13:00
13:15
13:30
13:45
14:00
how can I get this output in MATLAB??? please help and advice...
2 个评论
Jan
2012-7-5
编辑:Jan
2012-7-5
Please add any details by editing the question, because it is not clear, what you want to achieve and which level of variability you want.
In addition it is recommended to use meaningful tags, because they are used to classify the questions. Nearly all questions concern "Matlab code". I'm not able to give better tags by my own, because you did not specify, if your problem concerns a TIMER, SPRINTF, FPRINTF to the command window or to a file, a GUI, etc.
采纳的回答
Andrei Bobrov
2012-7-5
编辑:Andrei Bobrov
2012-7-6
try
datestr(datenum(0,0,0,12,(0:15:15*9)',0),'HH:MM')
ADD after Samer's answer
m=15;
id = [6 16];
time1 = cellstr(datestr(datenum(0,0,0,12,m*(1:diff(id)+1),0),'HH:MM'));
xlswrite('1.xlsx',time1,1,sprintf('A%d',id(1)));
5 个评论
Kevin Claytor
2012-7-5
Looking at the documentation for datenum (<http://www.mathworks.com/help/techdoc/ref/datenum.html>) it looks like the minute increment is set by the line;
(0:15:15*9)'
in his code above, you would just have to change that to get different increment values (replace 15 -> 30 or 60).
更多回答(4 个)
Luffy
2012-7-5
编辑:Luffy
2012-7-5
Clock=char('12:00','12:15','12:30','12:45','13:00','13:15','13:30','13:45','14:00');
for i = 1:size(Clock,1)
Clock(i,:)
end
Does this help you
Kye Taylor
2012-7-5
Try running this script... It has some ideas you might use, but it is hardly optimal.
startTimeString = '12:00';
stopTimeString = '14:00';
startTimeDV = datevec(startTimeString);
stopTimeDV = datevec(stopTimeString);
timeInterval = input('Enter the time step in minutes.\n');
thisTime = startTimeDV;
while thisTime(4) < stopTimeDV(4)
% a hack to count +60 minutes as hour
thisTime = datevec(datestr(thisTime));
thisTimeString = datestr(thisTime);
disp(thisTimeString(end-7:end))
thisTime(5) = thisTime(5) + timeInterval;
end
0 个评论
Luffy
2012-7-6
If you just want a loop with only 3 different intervals maybe this crude method can help Clock15=char('12:00','12:15','12:30','12:45','13:00','13:15','13:30','13:45','14:00');
Clock30=char('12:00','12:30','13:00','13:30','14:00');
Clock60=char('12:00','13:00','14:00');
based on gui if u use popup menu use switch case and give either of Clock15/Clock30/Clock60 to Clock and write a loop,
for i = 1:size(Clock,1)
Clock(i,:)
end
Does this help you
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!