Delete columns if sum of a group of 10 columns is zero
1 次查看(过去 30 天)
显示 更早的评论
I need to delete a group of coluns if their sum is equal a zero. I have 132 columns and 39174 lines. My data start at 14 line and 3 column. So if the sum of the columns 3 to 12 = zero, all those columns should be removed. And the code should keep searching for the next group of 10 columns equal zero (columns 13 to 22, 23 to 32, ...). Can anybody please help me?
I tried:
colToRemove = sum(Data1(15:end,3,10,end))==0;
Data1(:,colToRemove) = [];
0 个评论
采纳的回答
the cyclist
2023-5-20
编辑:the cyclist
2023-5-20
Here is one way.
for nc = 123:-10:3
colIdx = nc:(nc+9);
if sum(Data1(15:end,colIdx),"all")==0
Data1(:,colIdx) = [];
end
end
I worked right-to-left to check the columns, otherwise the indexing is complicated by the fact that one has deleted columns.
Also, you said that your data start at row 14, but you checked rows 15 and onward, so I used 15 as well. You may need to change that.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!