How to Resize data in column vector?

조회 수: 1 (최근 30일)
Sagar Dhage
Sagar Dhage 2014년 7월 31일
답변: Marco Castelli 2014년 7월 31일
I have column vector A=(0;0;0;0;0;232;222;245;342;232; 0;0;0;0;0;0;0345;323;324;345;343;0;0;0) How I can keep only one zero such that I get A=(0;232;222;245;342;232;0;0345;323;324;345;343;0;)?

답변 (3개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 7월 31일
A=[0;0;0;0;0;232;222;245;342;232; 0;0;0;0;0;0;0345;323;324;345;343;0;0;0]
idx=[0 A'==0 0]
ii=strfind(idx,[0 1])
jj=strfind(idx,[1 0])-1
ind=cell2mat(arrayfun(@(x,y) x:y-1,ii,jj,'un',0))
A(ind)=[]

Azzi Abdelmalek
Azzi Abdelmalek 2014년 7월 31일
편집: Azzi Abdelmalek 2014년 7월 31일
A=[0;0;0;0;0;232;222;245;342;232; 0;0;0;0;0;0;0345;323;324;345;343;0;0;0]
idx=[1 diff(A') ]==0 & A'==0
A(idx)=[]

Marco Castelli
Marco Castelli 2014년 7월 31일
A=[0;0;0;0;0;232;222;245;342;232; 0;0;0;0;0;0;0345;323;324;345;343;0;0;0];
idx = [];
for i1 = 2:length(A)
if and(A(i1)==0,A(i1-1)==0)
idx = [idx, i1];
end
end
A(idx) = [];

카테고리

Help CenterFile Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by