hi,i have a vector consisting of a very few non zero values and remaining all zeros, i need to extract only the non zero values but not zeros. I write a code like x=[0 0 0 0 0 1 0 5 0 9 6 0 0 0 0] n=length(x); for i=1:n if(x(i)~=0) y(i)=x(i); end end But it'll result something like y=[0 0 0 0 0 1 0 5 0 9 6 0 0 0 0] But, i need only non zero values. Can anyone tell me how to get only the non zero values from the vector.