0

I have a cell array with different datatypes, from an excel sheet that I need to read in, but which is beyond my control.

[~, ~, raw] = xlsread(xlsFile)

raw is now a r-by-c cell vector, for simplicity assume it has only one row. It will be filled with numbers (excel datenums to be exact) or other values such as [NaN] or ''. Thus, cell2mat() will not work.

What is the best way to extract only the number values? Is there a way to get an index where a cell contains a number?

Thanks.

1 Answer 1

0

Assuming just a single row, the following works to eliminate non-numeric values

rawData = {5,1.77,NaN,''};
rawDataIsNum = cell2mat(cellfun(@isnumeric,rawData,'UniformOutput',false)); %Returns matrix of true/false if real number or NaN
data = rawData(rawDataIsNum); %Returns cell of numbers

To remove the NaNs you can use something similar with @isnan

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .