필터 지우기
필터 지우기

Logicals with empty double column vectors

조회 수: 3 (최근 30일)
BdS
BdS 2019년 4월 25일
댓글: Jan 2019년 4월 25일
Hi
I have got this code:
a=Pf_ID; %--> 5x1cell
b=magic(5);
c=find(cellfun(@isempty,a)); %--> creates a double row vector with two entries as 2 elements in Pf_ID as empty
b(:,c)=[];
a(c,:)=[];
cc=find(cellfun(@isempty,a));
ccc=double.empty(0,1);
if cc==ccc % -->QUESTION: I cannot manage that this if statement becomes 'true' so that a=88. Do you have any hints?
a=88
end
  댓글 수: 1
Jan
Jan 2019년 4월 25일
The question is not clear:
I cannot manage that this if statement becomes 'true' so that a=88.
What do you get? What do you want instead? What exactly does "double.empty(0,1)"? Maybe you mean:
if isempty(cc)
a = 88;
end

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

채택된 답변

Guillaume
Guillaume 2019년 4월 25일
c=find(cellfun(@isempty,a));
a(c,:)=[];
The second line implies that a is 2D. Yet, find as used will return linear indices, so if a is indeed 2D the second line will error with 'index exceeds array dimension' if any element in column 2 or later is empty. You haven't explained what this code is meant to do but probably doesn't do what you want. It certainly doesn't do it safely.
You also haven't explained what your 2nd bit of code is meant to do. If you want to test that cc is empty, you use the exact same isempty test you've been using:
cc = find(cellfun(@isempty, a))
if isempty(cc)
a = 88;
end
Or you don't bother with the find, and just check that there's no true value returned by your cellfun:
if ~any(cellfun(@isempty, a))
a = 88;
end
  댓글 수: 1
Jan
Jan 2019년 4월 25일
As usual I mention, that cellfun('isempty', C) is more efficient than cellfun(@isempty, C).

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by