필터 지우기
필터 지우기

Time cell (or char) inside a double array

조회 수: 3 (최근 30일)
Engineer
Engineer 2014년 1월 20일
댓글: Till Rahlf 2014년 1월 20일
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
Amit
Amit 2014년 1월 20일
Example?
Engineer
Engineer 2014년 1월 20일
편집: Engineer 2014년 1월 20일
I get the time using getabstime function from a timeseries object...in output is a (for exapmle) 45x1 cell containing each one the time in string 09:45:43. I'd like to have the time expressed in the first column in a double precision array as it is shown above. Now, I solved the problem doing datenum(getabstime(ow86), as usual, but I'd like to have time express as above, in order to read "easily" the data

댓글을 달려면 로그인하십시오.

채택된 답변

Till Rahlf
Till Rahlf 2014년 1월 20일
편집: Till Rahlf 2014년 1월 20일
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
Engineer
Engineer 2014년 1월 20일
Thanks..I have earlier version of Matlab, but I found strjoin in File exchange http://www.mathworks.com/matlabcentral/fileexchange/31862-strjoin.
However, I'd like to have the cell showing the time 09:45:43 (1,1), 09:45:44 (2,1), 09:45:45 (3,1) etc. , as first column of an array that is made by double precision data in the other 4 columns...
Reading around, maybe this is not possible(?!)...I switched for the usual datenum, even if I'm not very satisfied by that!
Amit
Amit 2014년 1월 20일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Till Rahlf
Till Rahlf 2014년 1월 20일
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
Engineer
Engineer 2014년 1월 20일
I would like to show/print the time in the format HH:MM:SS instead of the datenum number in this double array. Probably, as said before, this is not possible because the time is not a number
Till Rahlf
Till Rahlf 2014년 1월 20일
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?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by