How to access specific integer values from a String and Convert into Integers?
Mostra commenti meno recenti
I have a MATLAB String "2018-04-24 04:30:00". I would like to access two specific values and save them as integers, i.e.
year = 2018
month = 04
I tried using str2num but it truncates the entire string because I can't apply it directly to the original string in that sense. My ultimate aim is to access the integer values of 2018 and 04 from this very string and save these into 2 seperate integer type variables - year and month. Any help in this regard from the MATLAB Community would be highly appreciated.
Thanks!
Risposta accettata
Più risposte (1)
madhan ravi
il 16 Nov 2018
Modificato: madhan ravi
il 16 Nov 2018
see datetime()
str="2018-04-24 04:30:00"
month=datetime(str,'Format','MM')
year=datetime(str,'Format','yyyy')
Categorie
Scopri di più su Numeric Types in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!