how to remove zeros from a cell array

조회 수: 6 (최근 30일)
RAJ DATTA
RAJ DATTA 2019년 3월 28일
댓글: RAJ DATTA 2019년 3월 29일
suppose i have a set of coordinate (which is given like [(x1,x2); (x3,x4); (0,0); (x5;x6)]), in which many are zeros, if i remove zeros with the following code, i am getting all rest coordinates in a single row [x1,x2,x3,x4,x5,x6], which is not desired. Please help. Thank you.
SOUVIK
for j1=1: length(xcor1)
for i1=1:9
if ~isempty(DistanceInClass2{j1}{i1})
CorInClass2{j1}{i1}(CorInClass2{j1}{i1}==0)=[];
end
end
end
  댓글 수: 1
Jan
Jan 2019년 3월 28일
You forgot to ask a question or mention, what you want to get instead. Do you want to remove rows, which contain a zero or only zeros?

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

채택된 답변

Jan
Jan 2019년 3월 28일
편집: Jan 2019년 3월 28일
for j1 = 1:length(xcor1)
for i1 = 1:9
Data = DistanceInClass2{j1}{i1};
if ~isempty(Data)
Data = Data(any(Data, 2), :);
CorInClass2{j1}{i1} = Data;
end
end
end
Maybe you want to replace any by all ? Alternatively:
Data(any(Data == 0, 2)) = []; % or: all()

추가 답변 (0개)

카테고리

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

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by