textscan format string for hours:minutes

Dear community,
While trying to get some time data from a .txt file with textscan() function I came across multiple issues. So I simplified my example to this:
txt = '00:01';
result = textscan(txt, '%{mm:ss}T');
And here is the result:
??? Error using ==> textscan
Badly formed format string.
Error in ==> example at 2
result = textscan(txt, '%{mm:ss}T');
Also tried %{mm:ss}D with the same result.
I'm very new to MATLAB, any help will be much appreciated.
Also, could this be because I'm using a very old version (R2007b)?
Thanks

3 commentaires

Stephen23
Stephen23 le 12 Août 2020
Modifié(e) : Stephen23 le 12 Août 2020
"could this be because I'm using a very old version (R2007b)?"
Yes.
Both the datetime and duration classes were introduced in R2014b along with their corresponding textscan format strings, so there is no way you could use that format string with R2007b.
munching
munching le 12 Août 2020
Thank you very much, this explains my issue. Matlab docs on textscan() says "Introduced before R2006a" so I though it should work.
Stephen23
Stephen23 le 12 Août 2020
Modifié(e) : Stephen23 le 12 Août 2020
"Matlab docs on textscan() says "Introduced before R2006a" so I though it should work."
The date at the bottom of the documentation page of most functions gives the MATLAB Release when the function was first available. However with any following Release afterwards a function can gain new features, change the order of its arguments, change the default behavior, etc. etc.
The documented behavior of your installed MATLAB Release is given in the installed documentation (i.e. help). You will find that your installed help does not mention datetime or duration classes (they don't exist) or the syntax that you tried to use with textscan. The online is certainly interesting to read, but it applies to the most current MATLAB Release, not the one you have installed.

Connectez-vous pour commenter.

 Réponse acceptée

hosein Javan
hosein Javan le 12 Août 2020
Modifié(e) : hosein Javan le 12 Août 2020
this works for me. I'm using 2016a.
txt = '00:01';
result = textscan(txt, '%{mm:ss}D')
result =
[00:01]
if you can't do this with your matlab. you can try to import the data as matrix rather than date and time format.
txt = '00:01';
% first colomn = mm, second column =ss
result = textscan(txt, '%d:%d')

2 commentaires

munching
munching le 12 Août 2020
Thank you for your answer. I'm okay having number of seconds as integer so I'll just modify the other part where the data comes from.
hosein Javan
hosein Javan le 12 Août 2020
you're welcome.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange

Produits

Version

R2007b

Community Treasure Hunt

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

Start Hunting!

Translated by