How to extract multi-format data from file?
Mostrar comentarios más antiguos
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?
Respuestas (3)
Walter Roberson
el 4 de Abr. de 2011
0 votos
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]
Rikard
el 11 de Abr. de 2011
Oleg Komarov
el 11 de Abr. de 2011
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))
Categorías
Más información sobre Text Files en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!