problem with converting data

조회 수: 2 (최근 30일)
lina
lina 2015년 6월 9일
댓글: Adam 2015년 6월 9일
Dear all, I have a problem error when I converted data in a cell '17 Mar 2010 10:00,02.510' I got this error First input must be of type double or string
how can I convert it to numbers?
thank you in advance.

채택된 답변

Adam
Adam 2015년 6월 9일
편집: Adam 2015년 6월 9일
str = someCellArray{1};
will extract that out of a cell array (if it is at index 1 in the cell array, change the index accordingly if not) into a string. For converting date strings to numeric functions like
doc datevec
doc datenum
tend to be used. str2num will not achieve this. But your string appears to be in an unsupported format when I did a quick test of those just now.
  댓글 수: 2
lina
lina 2015년 6월 9일
the cell is contain cell why I got only the first element even if I change the index?
Adam
Adam 2015년 6월 9일
I assumed you meant the data was in a cell rather than that each part of it was in an individual cell of a cell array.
cellfun( @(x) str2double(x), c, 'UniformOutput', false );
will convert the elements of cell array c into numbers, though letters will simply result in a [] in the corresponding cell of the output.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by