Reading a text file containing colon mark
이전 댓글 표시
I have a text file (a) contains words and numbers and colons. I would like to use the fscan and the fread function to get a time. However, the time is like this 2:30:20
I wonder, how can I do that such that there are cono(:) marks in between.
B=fread(a,time,'uint16');
I think the problem is in the uint16, but I don't know how to solve that.
Thanks in advance for your help
댓글 수: 1
Rik
2019년 5월 30일
Have you read the documentation for fread?
답변 (1개)
Krishna Anne
2019년 5월 30일
0 개 추천
Looks like you are getting the time as "Duration" class, Try one of these as required to fetch hours or seconds or minutes or milliseconds etc.
milliseconds(time) or
seconds(time) or
hours(time) or
minutes(time)
..........etc, provided time has class 'duration' you may check by typing class(time)
댓글 수: 16
Mohammed Qahosh
2019년 6월 1일
Walter Roberson
2019년 6월 1일
Which MATLAB release are you using? extractbetween() was added in R2016b, and ability to use " to delimit strings was added in R2017a.
Mohammed Qahosh
2019년 6월 1일
Walter Roberson
2019년 6월 1일
I suggest you look at fileread() and regexp()
Mohammed Qahosh
2019년 6월 2일
Walter Roberson
2019년 6월 2일
extractBetween is less flexibile than regexp is, so if there is a reason why you cannot use regexp then extractBetween will be even more difficult for you to get the information you need.
Mohammed Qahosh
2019년 6월 2일
Guillaume
2019년 6월 2일
Your implementation of the text parsing is very fragile. I agree with Walter, regexp is the way to go. If you attach an example file to your question, we can work out a reliable way to parse your text header.
Mohammed Qahosh
2019년 6월 2일
편집: Rik
2019년 6월 2일
Mohammed Qahosh
2019년 6월 2일
Guillaume
2019년 6월 2일
You've already given us the code in your question. As I said, it's very fragile. What I asked for is an example file to be parsed
Rik
2019년 6월 3일
@Guillaume the data inside the file is at the bottom of his comment. It is unclear to me however if there really are no newline characters in that file, or if the were just omited when posting here.
@Mohammed Can just just attach the file? You will have to put it in a zip first if it is not an otherwise supported file format. Then we can read the file ourselves and help you write more robust code.
Stephen23
2019년 6월 3일
Mohammed Qahosh 's "Answer" moved here:
These are the data from a file. There would be 2 spaces seperating each line, if all lines were in one line. I got this form once I copied them and pasted in matlab.
PCO Pixelfly USB Image
FileName: D:\experiment\MoleculeExp\FEM\Video\v190322ae\v190322ae_0.pco
File_version = 1
Date = 22.3.2019
Time = 15:26:42
Height = 600
Width = 800
Binning = 1
Exposure Time = 1000 msec
Average = 5
Temperature = 45
Pixel Rate = 12
Tip Voltage = 2150
Shutter State = 0
End
Mohammed Qahosh
2019년 6월 6일
카테고리
도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!