필터 지우기
필터 지우기

How to combine several matrices

조회 수: 2 (최근 30일)
Maryam Hamrahi
Maryam Hamrahi 2016년 8월 4일
댓글: Maryam Hamrahi 2016년 8월 4일
Elements of matrix B are row numbers of matrix A. The row number of matrix A start from 0. Matrix A has several zero rows.
produce matrix C:
when an element of matrix B refer to a zero row of matrix A, the row of matrix B should be replaced with zero.
For instance, I would like to produce Matrix C.
A =
0.0 0.0
0.4 0.8
0.0 0.0
0.2 0.6
B=
1 0
0 2
3 1
2 3
2 1
C=
0 0
0 0
3 1
0 0
0 0

채택된 답변

Guillaume
Guillaume 2016년 8월 4일
It's not clear from your description what happens when one of the column of a row of A is 0 and the other isn't.
This is one way to produce the output you want
C = B;
C(any(A(B+1) == 0, 2), :) = 0
Note that the output of
C = B;
C(A(B+1) == 0) = 0
would have made more sense to me.
  댓글 수: 1
Maryam Hamrahi
Maryam Hamrahi 2016년 8월 4일
Many thanks Guillaume.
This answer is correct.
C = B;
C(any(A(B+1) == 0, 2), :) = 0

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by