How to convert char to number?
Ältere Kommentare anzeigen
I have a data set that I am trying to format as follows:
month = data (:, 2); % (2276x1)
month =sprintf('%02d\n',month)
The problem is this gives me:
Name Size Bytes Class
month 1x6828 13656 char
I need it to be a single column of NUMBER data (2276x1) in the format I specified. I tried using str2num but this makes my data lose the formatting I want.
Please help and thank you!
5 Kommentare
Azzi Abdelmalek
am 10 Jun. 2016
Bearbeitet: Azzi Abdelmalek
am 10 Jun. 2016
Can you post a sample of your data?
Sandy
am 10 Jun. 2016
Bearbeitet: Azzi Abdelmalek
am 10 Jun. 2016
Sandy
am 10 Jun. 2016
Azzi Abdelmalek
am 10 Jun. 2016
When you write:
a=05
This number will be displayed as 5. The only way to display it with padded 0 is to use a string.
sprintf('%02d',5)
Image Analyst
am 10 Jun. 2016
Don't use month as a variable name because it's a built-in function. What does data represent, and especially column 2 of data? Why is month 2276 characters long? The month names I know of are less than 10 characters, like September.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Data Type Conversion finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!