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

Jan
Jan 2012년 11월 4일
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 2012년 11월 5일
the error mesage is: Index exceeds matrix dimensions.

댓글을 달려면 로그인하십시오.

 채택된 답변

Matt J
Matt J 2012년 11월 4일

1 개 추천

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

댓글 수: 2

Jwana
Jwana 2012년 11월 5일
error message : Index exceeds matrix dimensions.
Matt J
Matt J 2012년 11월 5일
편집: Matt J 2012년 11월 5일
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'

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2012년 11월 4일
편집: Azzi Abdelmalek 2012년 11월 4일

0 개 추천

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

Jan
Jan 2012년 11월 4일
편집: Jan 2012년 11월 4일
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 2012년 11월 5일
Thank you for your responses, how ever ;it gives error message : Matrix index is out of range for deletion.
Azzi Abdelmalek
Azzi Abdelmalek 2012년 11월 5일
편집: Azzi Abdelmalek 2012년 11월 5일
I did a big mistake, try Simon's code. And post a sample of your data

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2012년 11월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by