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

4 次查看(过去 30 天)
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)

采纳的回答

Walter Roberson
Walter Roberson 2012-7-2
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) ?

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by