Hi,
I have C{1,1}<1500x1 cell> which contains data like:
'10/21/2013 13:11:34.0289993'
'10/21/2013 13:11:34.1289978'
'10/21/2013 13:11:34.2289962'
'10/21/2013 13:11:34.3290023'
'10/21/2013 13:11:34.4290008'
'10/21/2013 13:11:34.5289993'
'10/21/2013 13:11:34.6289978'
'10/21/2013 13:11:34.7289962'
I need to convert this cell to double,I used:
C =cellfun(@str2double,C,'un',0);
but it replaces all data with NaN !
can someone help me with that?
best, Navid

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 4월 12일
편집: Azzi Abdelmalek 2014년 4월 12일

0 개 추천

D={'10/21/2013 13:11:34.0289993'
'10/21/2013 13:11:34.1289978'
'10/21/2013 13:11:34.2289962'
'10/21/2013 13:11:34.3290023'
'10/21/2013 13:11:34.4290008'
'10/21/2013 13:11:34.5289993'
'10/21/2013 13:11:34.6289978'
'10/21/2013 13:11:34.7289962'}
s=regexp(D,'\.','split')
a=cellfun(@(x) x{1},s,'un',0)
b=cellfun(@(x) x{2},s,'un',0)

댓글 수: 6

Navid
Navid 2014년 4월 12일
firstly thanks for your help,
I used:
F= datenum(C{1,1}(:,1),'mm/dd/yyyy HH:MM:SS');
but I got this error:
Error using datenum (line 179)
DATENUM failed.
Error in V2 (line 28)
F= datenum(C{1,1}(:,1),'mm/dd/yyyy HH:MM:SS');
Caused by:
Error using dtstr2dtnummx
Failed on converting date string to date number.
and one more thing,if you notice my data is not just date and time,after the time there is 7 digit number,I also need that.
I appreciate if help me with that.
Azzi Abdelmalek
Azzi Abdelmalek 2014년 4월 12일
WHy D{1,1}(:,1) ?
Azzi Abdelmalek
Azzi Abdelmalek 2014년 4월 12일
편집: Azzi Abdelmalek 2014년 4월 12일
The 7 digit are double or char? for example 0289993 if you convert it to double, it becomes 6 digits 289993
Azzi Abdelmalek
Azzi Abdelmalek 2014년 4월 12일
Look at edited answer
Azzi Abdelmalek
Azzi Abdelmalek 2014년 4월 12일
What this has to do with your initial question?
Navid
Navid 2014년 4월 12일
after getting this problem,I tried to overwrite the second column with the old values like this:
C =cellfun(@str2double,C,'un',0);
C(1,2)= dataArray(1,2);
VarName1 = cell2mat(C(:,1));
VarName1(isnan(VarName1)) = 0 ;
VarName2 = cell2mat(C(:,2));
VarName2(isnan(VarName2)) = 0 ;
but know for VarName1 every thing is ok but for VarName2 I get this error:
Error using cell2mat (line 53)
Cannot support cell arrays containing cell arrays or objects.
Error in Untitled2 (line 26)
VarName2 = cell2mat(C(:,2));
that's why I wanted to convert C{1,2} to double.

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

카테고리

도움말 센터File Exchange에서 Calendar에 대해 자세히 알아보기

제품

태그

질문:

2014년 4월 12일

댓글:

2014년 4월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by