Time cell (or char) inside a double array
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Engineer
am 20 Jan. 2014
Kommentiert: Till Rahlf
am 20 Jan. 2014
Hello, I have a 45x1 cell array, that I can convert to 45x8 char... the single cell is showing time, for example '09:45:46' ..
now, I would like to put this column as the first column of a double precision data array D.
I tried several things I was reading around, but I haven't found anything that could give me the right time as I see it here.
Some tips? Thanks
2 Kommentare
Akzeptierte Antwort
Till Rahlf
am 20 Jan. 2014
Bearbeitet: Till Rahlf
am 20 Jan. 2014
which matlab release do you use?
dateCells = {'09:45:46','09:45:49'}
dateString = strjoin(dateCells, sprintf('\n'))
result = textscan(dateString, '%d:%d:%d') % for integer results
result = textscan(dateString, '%f:%f:%f') % for double results
2 Kommentare
Amit
am 20 Jan. 2014
Okay the problem is the 09:45:43 is not double precision. So you cannot express it as double precision. The closest I can say you can do it 094543 which is a number.
Weitere Antworten (1)
Till Rahlf
am 20 Jan. 2014
What is exactly the result you expect?
Can you give an example for the cell array "dateCells "?
dateCells = {'09:45:43','09:45:44','09:45:45'}
expectedResult = ???
2 Kommentare
Till Rahlf
am 20 Jan. 2014
Yes, it is right. The character ":" can not be represented by a double number.
Alternatively you can have numbers like Amit wrote:
result = [
094543 ...
094544 ...
094545 ...
]
Or in stead of one double time column, you could have 3, like
result = [ 09 45 43 ...
09 45 44 ...
09 45 45 ...
]
Is that solution applicable?
Siehe auch
Kategorien
Mehr zu Numeric Types finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!