is not equal in cellarray

7 次查看(过去 30 天)
Jwana
Jwana 2012-11-4
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
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
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 个评论
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by