How to consider elements from two different column matrix and perform set of arithmetical operation?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I am having two 7*1 column matrix. One matrix consists of 3 bit binary numbers and another matrix consists of 1 bit binary number. Now I have to perform some set of arithmetical equations by considering elements in both matrix. I have to repeat the arithmetical calculation 7 times. First time I will choose 1st element from matrix A and assume that only this element is active and remaining elements are inactive. The arithmetic operation performed is B-1. For example at first 110 is selected and assumed this number only is active and first element from B is subtracted with 1. Remaining elements are assumed inactive, so the value to B is assumed as 0.
Example:
A= [110; 101; 011; 111; 100; 001; 010]
B= [1; 1; 0; 0; 1; 0; 1]
Expected output:
1st choice - 110 assumed active, so corresponding B element is 1, hence (B-1) 1-1=0, remaining elements are assumed inactive, so B is considered as 0 for remaining 6 elements in matrix A. Hence expected results are [(1-1=0), (0-1=-1), (0-1=-1), (0-1=-1), (0-1=-1), (0-1=-1), (0-1=-1)].
2nd choice - 101 assumed active, so corresponding B element is 1, hence (B-1) 1-1=0, remaining elements are assumed inactive, so B is considered as 0 for remaining 6 elements in matrix A. Hence expected results are [(0-1=-1), (1-1=0), (0-1=-1), (0-1=-1), (0-1=-1), (0-1=-1), (0-1=-1)].
3rd choice - 011 assumed active, so corresponding B element is 0, hence (B-1) 0-1=0, remaining elements are assumed inactive, so B is considered as 0 for remaining 6 elements in matrix A. Hence expected results are [(0-1=-1), (0-1=-1), (0-1=-1), (0-1=-1), (0-1=-1), (0-1=-1), (0-1=-1)].
C= 1st choice 2nd choice 3rd choice 4th choice 5th choice 6th choice 7th choice
0 -1 -1 -1 -1 -1 -1
-1 0 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 0 -1 -1
-1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 0
0 Kommentare
Akzeptierte Antwort
Voss
am 12 Dez. 2022
% A = [110; 101; 011; 111; 100; 001; 010]; % final result doesn't depend on the
% value of A (is that right?)
B = [1; 1; 0; 0; 1; 0; 1];
N = numel(B);
C = eye(N) - 1;
C(1:N+1:end) = B-1
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!