serial data to text format correction
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
Hello!,
I want to import some data to Matlab. I am sending a data package over serial and saving it into a text file. The data contains 3 values saparate by a coma and at the end of the line a '\n'. In total I send 24 ascii characters per line.
The correct format should look like this:
value1(float),value2(float) ,value3(long) '\n'
115.4,1.859 ,230974
115.4,1.855 ,230975
115.4,1.854 ,230976
There are some spaces between value 2 and the coma and value 3 and the '\n'. These are empty char, leaving free characters for higher values since these variables increase in value over time.
From time to time I get an unwanted carrier return in the text file:
115.4,1.
859 ,230979
115.4,1.857 ,230980
115.4,1.862 ,230
981
115.4,1.868 ,230982

Is there a way to give the correct format to the data when this happens? Something like ignore the carrier [carriage (dpb)] return if happens in less than 23 characters. I have tried with textscan but I don't get the correct combination of parameters to do this.
thank you!
댓글 수: 1
dpb
2020년 7월 3일
Are you writing the datastream or just trying to read it? The better solution would be to find some way to eliminate the source of the problem.
If you can't prevent transmission errors, about all you can do is read the file in a line-by-line fashion and parse each in turn, handling correctable transmission errors as you go. Not necessarily a trivial process.
답변 (0개)
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!