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')