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에서 Install Products에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by