将 hh:mm 时间转换为十进制时间(Matlab)

编程入门 行业动态 更新时间:2024-10-23 15:19:11
本文介绍了将 hh:mm 时间转换为十进制时间(Matlab)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试使用 Matlab 以十进制小时获取日出和日落时间.请看下面的代码.我已经到了结果是 2 1x2 单元格"的地步.时间表示为hh:mm"的阵列;在第一个单元格中.我想将其转换为十进制时间,例如 '08:41' 到 8.68333 作为双数组.我该怎么做?

I am trying to obtain the time of sunrise and sunset in decimal hours using Matlab. Please see the following code. I already got to the point where the result is 2 1x2 "cell" arrays with time indicated as "hh:mm" in the first cell. I would like to convert it to decimal time, for example '08:41' to 8.68333 as a double array. How can I do this?

谢谢.

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/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.例如:

you can cast to datenum, take day-fraction from that and multiply by 24. Ex:

f = rem(datenum('08:41', 'HH:MM'), 1)*24 % format is optional
%f =
%    8.6833

这篇关于将 hh:mm 时间转换为十进制时间(Matlab)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 12:18:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1393559.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时间   转换为   mm   hh   十进制

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!