Find numeric columns in a cell array
조회 수: 19 (최근 30일)
이전 댓글 표시
Hi,
I would like to use gplotmatrix on a dataset data, which contains mixed data (numeric and strings). However, gplotmatrix works on numeric data, so I need to convert my dataset to a matrix. As far as I understand, the only way is to do this is by
C=dataset2cell(data)
X=cell2mat(C)
However, the second command doesn't work, because C contains non-numeric columns. Is there a way to find which columns of a cell array contains only numbers? Thanks a lot,
Sergio
댓글 수: 0
채택된 답변
Jos (10584)
2014년 7월 3일
% C is a cell array, like
C = {1 2 3 4 5 ; 11 '12' 13:15 14 []}
q = cellfun(@(x) isnumeric(x) && numel(x)==1, C) % true for elements of C that are numerical scalars
IsAllNum = all(q,1) % true for columns of C that have only numerical scalars
X = cell2mat(C(:,IsAllNum)) % select and convert
댓글 수: 1
Bilirubin
2018년 9월 19일
Does anyone know why isnan gives an error msg?
C = {1 2 3 4 5 ; 11 '12' 13:15 14 []}
q = cellfun(@(x) isnan(x) && numel(x)==1, C) % true for elements of C that are numerical scalars
추가 답변 (1개)
Pascal
2014년 7월 3일
If you know whole columns are either numeric or not,
cell2mat(C(:,find(cellfun(@isnumeric, C(1,:)))))
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!