if statement to check if the first column of a cell matrix is empty or nor
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Respuesta aceptada
Walter Roberson
el 2 de Jul. de 2012
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) ?
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!