Issues with comparing data read in form Excel (equals to)

Hello, this is my first post and hope someone can help.
I am writing a shot piece of code but I am coming up against a brick wall with an error.
Below is the code I have written.
%% Load txt file into Matlab
M = uigetfile('*.xlsx','Select the .xls-file'); % This get the file name only and puts it in M
[data,text] = xlsread(M); %data captures the "time" but converts it to number - test saves the rest
% M is the selected file that is read in
time = data*24;
% File now loaded into Matlab - Time not accurate but will still allow us
% to distinguish between one transmission bloak and the next
%% While loop -
d = ' ';
i = 1;
while d == ' '
i = i + 1; % i should equal 2 after first run
d = text(i,1); % row i, column 1 of the text read in
end
Below is the fail I am getting:
%??? Undefined function or method 'eq' for input arguments of type 'cell'.
%Error in ==> WAL_Analyser at 21
%end
I have tried different types of brackets, and spent hours trying different thing but couldnt find code that works.
Any questions let me know... the first few cells I would be looking at in the loop would be blank then when i = 6 I should receive text, and exit the loop. Thats what I had hoped anyway.
Thanks, Sean

 Respuesta aceptada

Hi,
the problem is the line
d = text(i,1);
which makes d a 1x1 cell array (for which the == fails, see error message). You should get the cell entry with curly braces:
d = text{i,1};
Second: you are comparing strings, but the == compares elementwise. So when d is not empty, the d=='' will fail again. Better: use
while isempty(d)
Titus

2 comentarios

And by the way: using find(~cellfun(@isempty, text(:,1)), 1, 'first') should give you the index you are searching for ...
Titus
Sean
Sean el 16 de Ag. de 2011
Ah I was going to say it still doesnt work, but after changing the line d = ' ' to d = '', taking out the space and making d "empty", it works, I now get my text assigned to d when i = 6 and exit the loop.
Also tried the second way, also works to list the cells which aren't empty.
Every day is a school day.
100% happy I came on here. Thanks Titus, you were very helpful

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

el 16 de Ag. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by