Deleting rows of an array

2 次查看(过去 30 天)
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