multiplication by taking into account the values when creating a matrix
Show older comments
A matrix:
A = [2 1 4 3; ...
10 15 20 10; ...
20 10 15 20]
B matrix:
B = [1 3 4; ...
4 5 6; ...
2 1 4; ...
3 5 1]
C matrix:
C = [50;100;25;10]
I need to create a new matrix. I will use the values in matrices A, B and C when creating this matrix.I will try to explain how I want to create my new matrix through an example.
The matrix we want to create will be a 2x4 matrix.
Values in matrix A are important. First of all, the values in the first column are checked. The value of A(1,1) is 2. so the second row values in B and C are multiplied. but in B there are three columns in the second row. We must choose one of the three columns. When choosing, we consider the values in the second and third rows of A. If it is 10, the first column in B matrix is multiplied by B(2,1). If it is 15, the second column in B matrix is multiplied by B(2,2). if it is 20, the third column in B matrix is multiplied by B(2,3).
New matrix :
[400 150 10 75;
25 50 50 100]
What code is required to create such a matrix?
Thanks for help !
3 Comments
This is a follow-up of: https://www.mathworks.com/matlabcentral/answers/1727035-do-matrix-multiplication-by-taking-different-values-according-to-the-range
Again the hint: Please post the data such, that the readers can use them by copy&paste to create an answer. It is useful to make it as easy as possible to suggest a solution.
Berfin Çetinkaya
on 26 May 2022
@Berfin Çetinkaya: please explain the output matrix in these two locations:
- you wrote out(1,4)=75, but
- A(2,4)=10 -> 1st column of B
- A(1,4)=3 -> 3rd row of B & C
- B(3,1)=2
- C(3)=25
- 2*25 -> out(1,4)=50
and also:
- you wrote out(2,1)=25, but
- A(3,1)=20 -> 3rd column of B
- A(1,1)=2 -> 2nd row of B & C
- B(2,3)=6
- C(2)=100
- 6*100 -> out(2,1)=600
In the latter case out(2,1)=25 seems an unlikely output value given that C(2)=100 (later multiplied by an integer).
Accepted Answer
More Answers (0)
Categories
Find more on Resampling Techniques in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!