How to convert a matrix of cell to type double.

조회 수: 6 (최근 30일)
hello_world
hello_world 2016년 7월 2일
댓글: James Tursa 2016년 7월 5일
Hello Friends,
I have a cell matrix X of size NxD as follows:
X = [5.1000] [3.5000] [1.4000] [0.2000] 'sunday'
[4.9000] [ 3] [1.4000] [0.2000] 'sunday'
[4.7000] [3.2000] [1.3000] [0.2000] 'monday'
[4.6000] [3.1000] [1.5000] [0.2000] 'tuesday'
[ 5] [3.6000] [1.4000] [0.2000] 'tuesday'
[5.4000] [3.9000] [1.7000] [0.4000] 'sunday'
I want to convert it to type double. The last labeled column could be either type 'text' or 'numeric'.
I will appreciate any advise!

채택된 답변

James Tursa
James Tursa 2016년 7월 2일
if( isnumeric(X{1,end}) )
result = cell2mat(X);
else
result = cell2mat(X(:,1:end-1));
end
  댓글 수: 2
hello_world
hello_world 2016년 7월 2일
This converts cell to double only to the numeric value, but discards the labeled string column in the cell. So this code is incomplete.
James Tursa
James Tursa 2016년 7월 5일
How do you want the text in the last column converted to double?

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

추가 답변 (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