Fastest way to access another matrix for all nonzero rows
조회 수: 1 (최근 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!