How to extract multi-format data from file?
显示 更早的评论
Hello, I want to extract information from two IMUs, from a textfile that looks like this:
A,70,00000000,0000000c,fffffefa;M,70,ffffff62,ffffff92,fffffda3;G,70,00000004,0000006e,00000001,ffffc4b0; A,71,fffffffa,fffffff9,fffffef1;M,71,0000002a,0000000f,fffffc77;G,71,0000001c,0000001a,ffffffb9,ffffc2c0;
and so on, where 70 and 71 is the ID of the two sensors and A, G, M is accelerometer, gyro and magnetometer, respectively. So I have a char, an int and 3 or 4 hex values (or, if you like, just a long string), separated by commas and semicolons..
In any way, how can I retrieve this and put this into a matrix or similar?
回答(3 个)
Walter Roberson
2011-4-4
0 个投票
textscan with a format of '%c,%f,%[01234567899abcdef],%[0123456789abcdef],%[0123456789abcdef];' repeated 3 times per line, and convert the hex text to numeric values afterwards
OR
fscanf() with %x in place of those %[01234567899abcdef]
Oleg Komarov
2011-4-11
Walter meant:
fid = fopen('C:\Users\Oleg\Desktop\test.txt');
data = fscanf(fid,'%c,%f,%x,%x,%x;%c,%f,%x,%x,%x;%c,%f,%x,%x,%x,%x;\n');
fid = fclose(fid);
data = reshape(data,16,[]).';
% A, M and G are stored in numeric format with ascii correspondence
char(data(:,1))
类别
在 帮助中心 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!