How to consider elements from two different column matrix and perform set of arithmetical operation?

1 次查看(过去 30 天)
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

采纳的回答

Voss
Voss 2022-12-12
% 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
C = 7×7
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 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by