How to change entries in matrix based on another matrix?

3 visualizzazioni (ultimi 30 giorni)
I am having two matrix of size 7*7 and 7*1. Now, i need to compare these two matrix and alter entries in one matrix based on second matrix. Also, during computation, i need to consider first column of matrix A as last column but computation order of matrix B does not change. The computation has to begin from second column of matrix A and first row of matrix B and ends with first column of matrix A and last row of matrix B. For example, second row second column of matrix A has element 1 and first row of matrix B has element 1, so expected output at matrix C is element 1 in second row of first column. Similarly, sixth row of third column in matrix A is 1 and element 1 is present in second row of matrix B, hence expected output at matrix C is element 1 in sixth row of second column and remaining terms are 0. Element 1 is present in fourth row of first column in matrix A and element 1 is present in last row of matrix B and hence, expected output at matric C is element 1 has to be present in fourth row of seventh column. Thank you in advance.
Example:
A=[0 0 0 1 0 0 0
0 1 0 0 0 0 0
0 0 0 0 1 0 0
1 0 0 0 0 0 0
0 0 0 0 0 1 0
0 0 1 0 0 0 0
0 0 0 0 0 0 1]
B=[1; 1; 0; 0; 1; 0; 1]
Expected output:
C=[0 0 0 0 0 0 0
1 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 1
0 0 0 0 1 0 0
0 1 0 0 0 0 0
0 0 0 0 0 0 0]
  1 Commento
Jiri Hajek
Jiri Hajek il 24 Gen 2023
Hi, your description is not meaningful, sorry. It is rather funny, because you did not mention any algebraic or logical operators, nor any other mathematical operations by which you wish to obtain the matrix C from A abd B. |If you need help with MATLAB, we need have amathematical prescription first and then you can get the way to implemment it in MATLAB.

Accedi per commentare.

Risposta accettata

Dyuman Joshi
Dyuman Joshi il 24 Gen 2023
A=[0 0 0 1 0 0 0
0 1 0 0 0 0 0
0 0 0 0 1 0 0
1 0 0 0 0 0 0
0 0 0 0 0 1 0
0 0 1 0 0 0 0
0 0 0 0 0 0 1];
B=[1; 1; 0; 0; 1; 0; 1];
A0=circshift(A,-1,2)
A0 = 7×7
0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0
C=A0.*(B')
C = 7×7
0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by