if statement to check if the first column of a cell matrix is empty or nor
1 回表示 (過去 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)
1 件のコメント
採用された回答
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 Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!