is not equal in cellarray
Mostrar comentarios más antiguos
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!!
Respuesta aceptada
Más respuestas (1)
Azzi Abdelmalek
el 4 de Nov. de 2012
Editada: Azzi Abdelmalek
el 4 de Nov. de 2012
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
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
el 5 de Nov. de 2012
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
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!