How to delete columns of a matrix that have fewer than 3 non-zero elements
3 次查看(过去 30 天)
显示 更早的评论
Hello,
How can I delete columns of a matrix that have fewer than 3 non-zero elements? Thank you!
采纳的回答
Wayne King
2012-3-1
Hi, I'm sure this isn't the most efficient way:
x =[
5 0 1 4 1
3 0 0 2 1
1 0 2 2 4
4 3 0 2 3
4 2 0 1 3];
for nn =1:size(x,2)
numz(nn) = length(find(x(:,nn)==0));
end
x(:,numz>2) = [];
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!