Reading a text file containing colon mark
Afficher commentaires plus anciens
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 commentaire
Rik
le 30 Mai 2019
Have you read the documentation for fread?
Réponses (1)
Krishna Anne
le 30 Mai 2019
0 votes
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 commentaires
Mohammed Qahosh
le 1 Juin 2019
Walter Roberson
le 1 Juin 2019
Which MATLAB release are you using? extractbetween() was added in R2016b, and ability to use " to delimit strings was added in R2017a.
Mohammed Qahosh
le 1 Juin 2019
Walter Roberson
le 1 Juin 2019
I suggest you look at fileread() and regexp()
Mohammed Qahosh
le 2 Juin 2019
Walter Roberson
le 2 Juin 2019
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
le 2 Juin 2019
Guillaume
le 2 Juin 2019
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
le 2 Juin 2019
Modifié(e) : Rik
le 2 Juin 2019
Mohammed Qahosh
le 2 Juin 2019
Guillaume
le 2 Juin 2019
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
le 3 Juin 2019
@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
le 3 Juin 2019
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
le 6 Juin 2019
Catégories
En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!