is not equal in cellarray

how to make a not equal if statement in cellarray?
I tried this one:
for i=1:length(levelxxx)
if ~isequal(levelxxx{i},level1_root)
levelxxx(i,:)=[];
end
end
but it is not working!!

2 comentarios

Jan
Jan el 4 de Nov. de 2012
Whenever you write "is not working" in a forum, it is useful and recommended to explain, what actually happens: do you get an error message (if so, post a complete copy of the message) or do the results differ from your expectations?
Jwana
Jwana el 5 de Nov. de 2012
the error mesage is: Index exceeds matrix dimensions.

Iniciar sesión para comentar.

 Respuesta aceptada

Matt J
Matt J el 4 de Nov. de 2012

1 voto

Maybe this?
idx = ismember(levelxxx(:,1),level1_root,'rows');
levelxxx= levelxxx(idx,:);

2 comentarios

Jwana
Jwana el 5 de Nov. de 2012
error message : Index exceeds matrix dimensions.
Matt J
Matt J el 5 de Nov. de 2012
Editada: Matt J el 5 de Nov. de 2012
Works fine for me:
>> levelxxx={'111','zz';'222','abgh';'111','hyur'}; level1_root='111';
>> idx = ismember(levelxxx(:,1),level1_root); levelxxx= levelxxx(idx,:)
levelxxx =
'111' 'zz'
'111' 'hyur'

Iniciar sesión para comentar.

Más respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 4 de Nov. de 2012
Editada: Azzi Abdelmalek el 4 de Nov. de 2012

0 votos

when the condition is true :
levelxxx(i,:)=[];
then the size of levelxxx will be reduced!
use
v_temp=levelxxx
for i=1:length(v_temp)
if ~isequal(v_temp{i},level1_root)
levelxxx(i,:)=[];
end
end

3 comentarios

Jan
Jan el 4 de Nov. de 2012
Editada: Jan el 4 de Nov. de 2012
Reducing the size of an array repeatedly causes the same troubles than a repeated growing: The need to re-allocate the new arrays wastes a lot of time. Better:
index = true(size(levelxxx)); % Pre-allocate
for ii = 1:length(v_temp) % avoid "i" as name of a variable
index(ii) = isequal(levelxxx{ii}, level1_root);
end
levelxxx = levelxxx(index, :);
Jwana
Jwana el 5 de Nov. de 2012
Thank you for your responses, how ever ;it gives error message : Matrix index is out of range for deletion.
Azzi Abdelmalek
Azzi Abdelmalek el 5 de Nov. de 2012
Editada: Azzi Abdelmalek el 5 de Nov. de 2012
I did a big mistake, try Simon's code. And post a sample of your data

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 4 de Nov. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by