MATLAB: Delete zero elements from vector

matrices

Hi
I have k (1,600) size, it contain zeros at 451-600 elements.
I want to delete these zero elements. At the end of this vector i want to add two elements with value equal to the last element .
thank you in advance

Best Answer

k = nonzeros(k);
k(end+1:end+2) = k(end)