matlab进制转换、时间函数

matlab

by lqx

进制转换

在这里插入图片描述

num = 255;
dec2bin(num)  % 输出二进制数 11111111
dec2hex(num)  % 输出十六进制数 FF

bin = '1101';
hex = 'FF';
bin2dec(bin)  % 输出十进制数 13
hex2dec(hex)  % 输出十进制数 255

dec2bin(5)  % 输出 '101'
dec2bin(5, 8)  % 输出 '00000101'
bin2dec('101')  % 输出 5

dec2hex(255)  % 输出 'FF'
dec2hex(255, 4)  % 输出 '00FF'
hex2dec('FF')  % 输出 255

dec2base(6, 6, 3)  % 输出 '010'
dec2base(255, 6, 4)  % 输出 '1103'
dec2base(6, 6, 3)  % 输出 '010'
dec2base(255, 6, 4)  % 输出 '1103'
base2dec('1103', 6)  % 输出 255

时钟函数

在这里插入图片描述

clock

C = clock;
year = C(1)
month = C(2)
day = C(3)
hour = C(4)
minute = C(5)
second = C(6)
%语法:C = clock,其中 C 是一个包含当前年、月、日、小时、分钟和秒的向量,
%格式为 [year, month, day, hour, minute, second]。

now

t = now; % 当前时间的总秒数
C = datevec(t) % 将秒数转换为年、月、日、小时、分钟和秒
%显示结果:
C =

   1.0e+03 *

    2.0230    0.0060    0.0160    0.0210    0.0080    0.0074

date

str = date % 返回当前日期字符串,例如 '16-Jun-2023'

datestr

D = clock;

% 返回当前时间的默认字符串格式,例如 '16-Jun-2023 15:30:00'
str1 = datestr(D)

% 返回指定格式的时间字符串,例如 '2023-06-16 15:30'
str2 = datestr(D, 'yyyy-mm-dd HH:MM')

C = datevec(t) % 将秒数转换为年、月、日、小时、分钟和秒
%显示结果:
C =

1.0e+03 *

2.0230    0.0060    0.0160    0.0210    0.0080    0.0074

### date

```matlab
str = date % 返回当前日期字符串,例如 '16-Jun-2023'

datestr

D = clock;

% 返回当前时间的默认字符串格式,例如 '16-Jun-2023 15:30:00'
str1 = datestr(D)

% 返回指定格式的时间字符串,例如 '2023-06-16 15:30'
str2 = datestr(D, 'yyyy-mm-dd HH:MM')
  • 9
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值