Modifing a specific matrix that is corresponding to an indexing matrix

조회 수: 1 (최근 30일)
Hello everyone,
I have an indexing matrix A and regular matrix B. Each row of A has only 1 (one), the position index of this 1 should be traced to the matrix B and multiplied by 10. For example,
A=[ 2 1 5 4 3;
3 2 1 4 5;
1 3 2 5 4;
2 5 4 1 3]
B=[53 530 53 53 53;
19 19 190 19 19;
550 55 55 55 55;
45 45 45 450 45]
Thank you in advance!
  댓글 수: 3
ABDULAZIZ
ABDULAZIZ 2016년 4월 9일
편집: Azzi Abdelmalek 2016년 4월 9일
Hello Abdelmalek B is another matrix that has no relation with A, B was like this
B=[53 53 53 53 53;
19 19 19 19 19;
55 55 55 55 55;
45 45 45 45 45]
but after the modifying based on the specific indexing matrix A becomes:
B=[53 530 53 53 53;
19 19 190 19 19;
550 55 55 55 55;
45 45 45 450 45]

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

채택된 답변

Matt J
Matt J 2016년 4월 9일
B(A==1)=10*B(A==1)

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 9일
I suppose your data are
A=[ 2 1 5 4 3;
3 2 1 4 5;
1 3 2 5 4;
2 5 4 1 3]
B=[53 53 53 53 53;
19 19 19 19 19;
55 55 55 55 55;
45 45 45 45 45]
% The code
idx=A==1
B(idx)=B(idx)*10

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by