Effacer les filtres
Effacer les filtres

is not equal in cellarray

7 vues (au cours des 30 derniers jours)
Jwana
Jwana le 4 Nov 2012
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 commentaires
Jan
Jan le 4 Nov 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 le 5 Nov 2012
the error mesage is: Index exceeds matrix dimensions.

Connectez-vous pour commenter.

Réponse acceptée

Matt J
Matt J le 4 Nov 2012
Maybe this?
idx = ismember(levelxxx(:,1),level1_root,'rows');
levelxxx= levelxxx(idx,:);
  2 commentaires
Jwana
Jwana le 5 Nov 2012
error message : Index exceeds matrix dimensions.
Matt J
Matt J le 5 Nov 2012
Modifié(e) : Matt J le 5 Nov 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'

Connectez-vous pour commenter.

Plus de réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 4 Nov 2012
Modifié(e) : Azzi Abdelmalek le 4 Nov 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 commentaires
Jwana
Jwana le 5 Nov 2012
Thank you for your responses, how ever ;it gives error message : Matrix index is out of range for deletion.
Azzi Abdelmalek
Azzi Abdelmalek le 5 Nov 2012
Modifié(e) : Azzi Abdelmalek le 5 Nov 2012
I did a big mistake, try Simon's code. And post a sample of your data

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by