matlabdatasetcell-array

MATLAB: Find numeric columns in a cell array


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 know, the only way is to do this is through

C=dataset2cell(data)
X=cell2mat(C) 

However, the second command throws an error, because C contains non-numeric columns. Is there a way to find which columns of a cell array are purely numeric?


Solution

  • Use cellfun with @isnumeric function handle -

    numeric_cols = find(all(cellfun(@isnumeric,C)))
    

    Related useful pointers -