How to Resize data in column vector?
Afficher commentaires plus anciens
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;)?
Réponses (3)
Azzi Abdelmalek
le 31 Juil 2014
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
le 31 Juil 2014
Modifié(e) : Azzi Abdelmalek
le 31 Juil 2014
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
le 31 Juil 2014
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) = [];
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!