How to Resize data in column vector?

3 次查看(过去 30 天)
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