有没有办法分开
`vector=[0345;0230;0540;2340]`
到
`vec_1=[03;02;05;23]`
和
`vec_2=[45;30;40;40]`
答案 0 :(得分:3)
怎么样
vector=[0345;0230;0540;2340];
v1 = mod(vector,100)
(vector-v1)/100
答案 1 :(得分:2)
我的解决方案:
v = [0345;0230;0540;2340];
vv = num2str(v,'%04d'); %# convert to strings, 4 digits, fill with zeros
v1 = str2num( vv(:,1:2) ) %# extract first two digits, convert back to number
v2 = str2num( vv(:,3:4) ) %# extract last two digits, convert back to number
结果:
v1 =
3
2
5
23
v2 =
45
30
40
40
当然,如果您希望将结果作为字符串的单元格数组(保留任何前导零),请使用:
>> v1 = cellstr(num2str(v1,'%02d'))
v1 =
'03'
'02'
'05'
'23'