![](/img/trans.png)
[英]Plotting a set of data with time in hh:mm format in x axis in matlab
[英]Convert hh:mm time to decimal time (Matlab)
我正在嘗試使用 Matlab 以十進制小時數獲取日出和日落時間。 請看下面的代碼。 我已經到了結果是 2 1x2 "cell" arrays 的地步,時間在第一個單元格中顯示為 "hh:mm"。 我想將其轉換為十進制時間,例如將 '08:41' 轉換為 8.68333 作為雙精度數組。 我怎樣才能做到這一點?
謝謝。
clear all;
close all;
tic;
startDate = datetime(date, 'ConvertFrom', 'yyyymmdd', ...
'TimeZone', 'UTC', ...
'Format', 'd MM yyyy');
%% Download sunset and sunrise time
date_day = day(startDate);
date_month = month(startDate);
date_year = year(startDate);
% Brussels
fullURL1 = sprintf('http://api.aladhan.com/v1/calendarByCity?city=Brussels&country=Belgium&method=2&month=%02d&year=%04d',date_month,date_year);
api = fullURL1;
url = [api 'country'];
S = webread(url);
sunrise = sprintf('S.data(%02d).timings.Sunrise',date_day);
sunrise = eval(sunrise);
sunrise = strsplit(sunrise);
sunset = sprintf('S.data(%02d).timings.Sunset',date_day);
sunset = eval(sunset);
sunset = strsplit(sunset);
clearvars url fullURL1 api S
您可以轉換為datenum ,從中取日分數並乘以 24。例如:
f = rem(datenum('08:41', 'HH:MM'), 1)*24 % format is optional
%f =
% 8.6833
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.