delete zero elements from vector

조회 수: 6 (최근 30일)
zina shadidi
zina shadidi 2020년 11월 18일
댓글: zina shadidi 2020년 11월 18일
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

채택된 답변

Stephen23
Stephen23 2020년 11월 18일
k = nonzeros(k);
k(end+1:end+2) = k(end)
  댓글 수: 1
zina shadidi
zina shadidi 2020년 11월 18일
Thanks alot Stephen Cobeldick ;
its work with the vector. please let me ask you if I have an (n by m ) matrix how can i grow it ,
I have an array of (452x 6) and i want to make it grow by adding 2 column

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Setsuna Yuuki.
Setsuna Yuuki. 2020년 11월 18일
You can use:
k(k==0) = [];
k(length(k)+1:length(k)+2) = k(1,length(k));
  댓글 수: 1
zina shadidi
zina shadidi 2020년 11월 18일
thank you very much Bastian Arturo Romero Mardones

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by