Converting a string Array into a Char array
Afficher commentaires plus anciens
Hello I have an array of strings called time, they all have the format: 22:39:04.502727 hours:minutes:seconds and I want to convert all of them into a number where its minutes.seconds, so how would I do that?
3 commentaires
per isakson
le 18 Août 2017
Modifié(e) : per isakson
le 18 Août 2017
Give us an example. To what do you want to convert the string, 22:39:04.502727 ? To the number 39.04502727 ??? That's what I read.
The title, "Converting a string Array into a Char array", and the question, "to convert all of them into a number" say different things.
Leo Quintanar
le 18 Août 2017
Walter Roberson
le 18 Août 2017
If you are using somwhere around R2015b-ish or later, then you can convert your times to datetime objects and use the datetime objects as your x coordinate, without needing to convert to integers.
Réponses (2)
Sean de Wolski
le 17 Août 2017
Use datetime and then change the Format to that which you desire.
dt = datetime('22:39:04.502727','InputFormat','HH:mm:ss.SSSSSS')
dt.Format = 'mm:ss'
1 commentaire
Leo Quintanar
le 18 Août 2017
Modifié(e) : Walter Roberson
le 18 Août 2017
per isakson
le 19 Août 2017
Modifié(e) : per isakson
le 19 Août 2017
"My intentions are to graph time vs. temp."
[date, time, temp ] = textread('h:\m\cssm\data.txt','%s %s %f', 8 );
dt = datetime( time, 'InputFormat','HH:mm:ss.SSSSSS' );
sdn = datenum( time, 'HH:MM:SS.FFF' ); % the old way
plot( sdn, temp ), datetick
plot( dt, temp )
where data.txt contains
2017-08-19 22:39:04.502727 26.404006797400000
2017-08-19 22:40:04.502727 26.404006797400000
2017-08-19 22:41:04.502727 26.404006797400000
2017-08-19 22:42:04.502727 26.404006797400000
2017-08-19 22:43:04.502727 26.404006797400000
2017-08-19 22:44:04.502727 26.404006797400000
2017-08-19 22:45:04.502727 26.404006797400000
2017-08-19 22:56:04.502727 26.404006797400000
produces two identical(?) diagrams. I guess, there are rounding errors.
You didn't mean
plot( temp, dt )
2 commentaires
Leo Quintanar
le 20 Août 2017
per isakson
le 20 Août 2017
I run this example on R2016a. Which release do you use? datetime was "Introduced in R2014b"
Catégories
En savoir plus sur Dates and Time 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!