Deleting rows of an array

조회 수: 2 (최근 30일)
Nikolas Spiliopoulos
Nikolas Spiliopoulos 2017년 4월 4일
댓글: KSSV 2017년 4월 4일
Hi all,
I have an array 48X365, where some of the columns are zero!
Is there any way to delete them and get an array without these columns?
The thing is that the columns appear randomly
thanks!

채택된 답변

Guillaume
Guillaume 2017년 4월 4일
if you want to delete columns with all 0:
yourmatrix(:, all(yourmatrix == 0)) = [];
if you want to delte columns with any 0:
yourmatrix(:, any(yourmatrix == 0)) = [];

추가 답변 (1개)

KSSV
KSSV 2017년 4월 4일
Let data be your matrix where few columns are zeroes. Use:
data(:, sum(data,1)==0) = [] ; % removes columns with zeroes
  댓글 수: 2
Stephen23
Stephen23 2017년 4월 4일
Buggy code: if the column contains [-1;1], then this code would incorrectly identify it and remove it.
Guillaume's answer is the correct way to do this.
KSSV
KSSV 2017년 4월 4일
Yes....it flashed me now...

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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by