Hi :) I forgot to mention that the values in the .txt file is hex and at some point i guess i also have to convert that do decimal values (but I think I have an idea about how to do that). :)
Read continuous data from one txt file, where there is more that one header
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Annizette Larsen
am 24 Jan. 2018
Beantwortet: Annizette Larsen
am 29 Jan. 2018
Hi :)
I have a .txt file (I have attached it here). Which consists of continuous data output, where the 26 first "words/numbers" are the information data (it stops at 44D where the raw data continue after that). So from 27 and 1101 output later is the first raw data. (it always stops with 0 0 0 0 0).
The second part also starts with sSN LMDscandata where the first 26 "words/numbers" are the information data, and so on like the first one.
My question then is: I would like a script that can read and display this data, but i don't know how to read in this continuous data from one txt file, and also somehow display it in 3D. I am pretty new to matlab so any help is really appreciated :) :)
Akzeptierte Antwort
Guillaume
am 24 Jan. 2018
Splitting your file into each block is trivial since the blocks are actually separated by control character \03 and \02, so:
wholecontent = fileread('LidarTestData.txt'); %read the whole file in one go
blocks = strsplit(wholecontent, char([3 2]));
However, if you want to actually split each block between its 3 components (LMDscandata, DIST1 and RSSI1 as far as I can tell) and convert the hexadecimal to numbers, then I would not bother with the above and use a regular expression instead:
wholecontent = fileread('LidarTestData.txt'); %read the whole file in one go
blockparts = regexp(wholecontent, 'sSN LMDscandata ([0-9A-F ]+) DIST1 ([0-9A-F ]+) RSSI1 ([0-9A-F ]+)', 'tokens');
blockparts = vertcat(blockparts{:}); %generates a nblock x 3 cell array
blocknums = cellfun(@(b) hex2dec(strsplit(b)), blockparts, 'UniformOutput', false)
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Use COM Objects in MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!