MATLAB: If statement to check if the first column of a cell matrix is empty or nor

if statement

Dear all,
I load an excel file into Matlab. For example:
[num,txt,raw]=xlsread('koi.xlsx');
data=num; % contains only numbers or empty cells
data=num2cell(data)
size1=size(data);
If the first column in "data" is empty i use
data=[zeros(size1(1,1) ,1) num2cell(data)]
if not, I use the initial output
data=num2cell(data)
But is is a bit painful to check every file to see if the 1rst column is empty or not
So, What I am looking for is something like
[num,txt,raw]=xlsread('koi.xlsx');
data=num; %
data=num2cell(data)
size1=size(data);
if data(:,1) is empty i fill it with an
data=[zeros(size1(1,1) ,1) num2cell(data)]
else
data=num2cell(data)

Best Answer

I do not have an MS Windows system to test with, but it looks to me from the documentation that this might be appropriate:
[num,txt,raw]=xlsread('koi.xlsx');
if all(isnan(num(:,1)))
data = [ cell(size(num,1),1), num2cell(num) ];
else
data = num2cell(num);
end
I wonder, though, whether this is really what you want to do? Do you want to change the NaN that indicate XLS emptiness so that the cells actually become empty? Or do you want to prefix a column of empty cells to the data read in, leaving the NaN that indicate XLS emptiness in place (as you are doing now) ?
Related Question