How to convert a minutes elapsed vector to time (hh:mm)?

14 ビュー (過去 30 日間)
Antonio Taveira
Antonio Taveira 2021 年 8 月 7 日
回答済み: Peter Perkins 2021 年 8 月 9 日
Hi,
On a continous 24 hour measurement, I have a vector of time elapsed in minutes since the beginning (0 to 1440). I know that the starting time of the measurement is 16:00. How to create a time vector (hh:mm) for each sample? The purpose is to add the time on the x axis of a plot.
My best try is using a loop that goes through each sample, with h (hour) starting at 16 and rounds the minutes. The issue is it must detect every hour change.
Looking forward for some help :)
for i=1:length(meas_SPL_all)
meas_SPL_all(:,3) = {h:round(meas_SPL_all(i,2))}
if round(meas_SPL_all(i,2) > 60
h = h + 1
end

採用された回答

Walter Roberson
Walter Roberson 2021 年 8 月 7 日
t = hours(16) + minutes(meas_SPL_all(:, 2));
t.Format = 'hh:mm';
  1 件のコメント
Antonio Taveira
Antonio Taveira 2021 年 8 月 8 日
Works great! Thanks, Walter.

サインインしてコメントする。

その他の回答 (1 件)

Peter Perkins
Peter Perkins 2021 年 8 月 9 日
"continous 24 hour measurement" sounds like you are dealing with time of day. If you add 600 minutes to hours(16), you will get
>> hours(16) + minutes(600)
ans =
duration
26 hr
which may not be what you want. If you want this to wrap to 04:00, add to an absolute time.
>> datetime(2021,8,9,16,0,0) + minutes(600)
ans =
datetime
10-Aug-2021 02:00:00

カテゴリ

Help Center および File ExchangeSpectral Measurements についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by