我从加速度计数据记录中读取了这组十六进制值:
35AC,2889,1899,0C4A,058B,FD46,F620,F001,EE44,EF08,EF46,F750,007F,0814,1369,21F3,34F0,45CE,5992,6D05,7C12,7FEF,7FF8,7FF8 ,7FF8,7FF8,7FD9,7F27,74A7,67D8,5826,468F,3621,2573,1326,0441,F88F,F1BF,F082,EADB,EAEE,EE04,F190,F89E,01F5,0B0C,155A,2721,3A20 ,48DC,5985,676A,721E,7C20,7FF8,7FEE,7F1B,
它应该以某种方式绘制一条正弦曲线,但我找不到正确的签名int16
导入方法,曲线从0跳到65535.
你能帮我吗?
我试过了sscanf(...,'%4x')
答案 0 :(得分:0)
签名的十六进制int16的sscanf
格式只是'%4i'
。不幸的是,它希望十六进制值以0x
开头,你明显不会这样。一种可能性是您可以按原样扫描它,然后手动将其转换为带符号的int16。一种可能的方法是:
input = sscanf(...,'%4x');
input16 = typecast(uint16(input),'int16');
值正在作为uint32读入,并由sscanf
函数自动转换为double。所以我们将它转换为uint16,然后将其转换为16位int(请注意,仅使用int16(input)
不起作用,因为它不会将INT16_MAX上的值转换为负值。)
答案 1 :(得分:0)
string = '35AC,2889,1899,0C4A,058B,FD46,F620,F001,EE44,EF08,EF46,F750,007F,0814,1369,21F3,34F0,45CE,5992,6D05,7C12,7FEF,7FF8,7FF8,7FF8,7FF8,7FD9,7F27,74A7,67D8,5826,468F,3621,2573,1326,0441,F88F,F1BF,F082,EADB,EAEE,EE04,F190,F89E,01F5,0B0C,155A,2721,3A20,48DC,5985,676A,721E,7C20,7FF8,7FEE,7F1B';
%// Your data as a string
string = [string ',']; %// add ending comma to reshape into groups of five chars
strings = reshape(string,5,[]).';
strings = strings(:,1:4); %'// each row is 4 chars representing a hex number
numbers = hex2dec(strings); %// convert each row to a number
ind = numbers>=32768;
numbers(ind) = numbers(ind)-65535; %// get rid of jumps
plot(numbers)
答案 2 :(得分:0)
非常感谢
以前的答案都是there。
假设sscanf替代方案更快。