Fastest way to access another matrix for all nonzero rows

1 回表示 (過去 30 日間)
lightroman
lightroman 2017 年 11 月 3 日
編集済み: per isakson 2017 年 11 月 3 日
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.

採用された回答

per isakson
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 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by