Read continuous data from one txt file, where there is more that one header

1 view (last 30 days)
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 :) :)
  1 Comment
Annizette Larsen
Annizette Larsen on 24 Jan 2018
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). :)

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 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)

More Answers (1)

Annizette Larsen
Annizette Larsen on 29 Jan 2018
Hi Again :)
I now get some data out via a 3d scatter plot (I have attached a jpg file of the matlab figure, with some text to explain what is what). There is also attached at picture of the object i have tried to scan. I have also attached my matlab code (I know it is not that pretty but i am very new at this).
My questions are: Question 1a: I have tried to change my axis of the plot so it looks better, when it comes for the visual understanding, but without any luck. Question 1b: And as you can also see, if you run the code and use the 3d view botton, then it does not look the best, the points are clogging (which could be because of some little shakings, when the sensor moves with a constant speed). (any Good advice on this is really appreciated)
Question 2: I want to do some analyse, preferable via point cloud. Is it something you can use matlab for?
What I want in the end, is to be able to look at at fence (with my lidar sensor), and tell if there is a large hole. ( which has to be done via data analysis and not just by looking at the point image)
Thank you so much, for taking your time to help me out !! :) :)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!