Fastest way to access another matrix for all nonzero rows
2 次查看(过去 30 天)
显示 更早的评论
Hi I am new to MATLAB and I have been looking on here for 20 minutes.
I am able to do this with multiple lines of code using find and reshaping but I wondered if theres a one or two line way.
The full row on matrix A must be zeros to discard it.
A = [ 4 8 2; 0 0 0; 1 4 6; 0 0 0]
B = [ 8 9 3; 2 8 1; 9 2 0; 1 4 2]
Desired result would be:
result = [8 9 3; 0 0 0; 9 2 0; 0 0 0]
The matrix is too large to select rows specifically. Please help.
0 个评论
采纳的回答
per isakson
2017-11-3
编辑:per isakson
2017-11-3
>> B( all( A==0, 2 ), : ) = 0
B =
8 9 3
0 0 0
9 2 0
0 0 0
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!