Array of time in seconds converted to Hours Minutes seconds.
3 次查看(过去 30 天)
显示 更早的评论
Ive two lots of data that gets stored in variables with the format 1 x yyy where yyy is the size of the datastring, ie a row of data not a column. The two strings are always of the same length to 1xyyy from the first data corresponds to 1xyyy from the seconds data stream. The first represents time in seconds since midnight and the second is my data which is to be modified.
So for example I have a variable called time,
42543 42544 52545 and so on
Then another variable with data
42.67 42.97 44.32 and so on.
I want the output to be,
YYYY MM DD HH MM SS.SS Data
YYYY MM DD HH MM SS.SS Data
YYYY MM DD HH MM SS.SS Data
I can use,
t = handles.mtime;
hours = floor(t / 3600);
t = t - hours * 3600;
mins = floor(t / 60);
secs = t - mins * 60;
to convert the time. And I need to add the data which will be called for elswhere. How do I use a for loop to convert the string? Do I need to rotate the data using rot 90 so its in a column?
0 个评论
回答(1 个)
dpb
2014-2-26
I'm not sure what part the 1xyyy plays, but if you know the beginning date simply use supplied Matlab date functions to get the date string. You'll have to use a cell array to associate the data value in the same array, however, since they're mixed types (string and double).
Assuming initial values are Y0, MO, D0 (year, month, day zero) then
dn=datevec(Y0, MO, DO, 0, 0, t.'); % datenum vector
dstr=datestr(dn,'yyyy mm dd HH MM SS.FFF');
will give you the date string and you can then just write
celldata={dstr data.'};
The above uses the "internal smarts" of datevec to rollover time fields correctly w/o having to take care of explicitly. It's a very useful feature.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!