do matrix multiplication by taking different values according to the range
Show older comments
A matrices :
2 1 3
7 1 3
2 8 6
5 9 4
B matrix: C matrix: D matrix:
0,1 0,4 0,6
0,7 0,1 0,5
0,8 0,5 0,6
E matrix :
10
20
15
(from the second row, i.e. except the first row)For values between 1 ,2,3 in matrix A, matrix B is checked.
For values 4, 5,6 in matrix A, matrix C is checked.
For values between 7,8,9 in matrix A, matrix D is checked.
For the 7 value written in the 2nd row of the A matrix (since it is between 5 and 9) the D matrix is checked. The value in the 2th row of the D matrix is taken. (the value of 0.6 is taken) (We got the value in row 2 because in the first row of matrix A, cell (1,1) it says 2)
Then it will look at the top number in the A matrix, for example 7 in the second row. For example, it writes 2. Since it writes the value 2, it takes the value 20 in the 2nd row in the E matrix.
Then 0.5 multiplied by 20. And this is used for all values in matrix A.
new matrix:
0,5*20 0,1*10 0,8*15
0,7*20 0,6*10 0,5*15
0,5*20 0,6*10 0,5*15
If we multiply these values, we get the following matrix:
new matrix:
10 1 12
14 6 7,5
10 6 7,5
Thank you for help !
10 Comments
Walter Roberson
on 25 May 2022
what is your question?
Jan
on 25 May 2022
What does this mean: "(from the second row, i.e. except the first row)For values between 1 ,2,3 in matrix A, matrix B is checked."?
I do not understand any sentence of the description. What does "checking a matrix" mean? Does B contain 2 columns or does "0,1" mean 0.1 ? What exactly is "0,5*20"? [0, 100], or 10? Please use dots as decimal points. Commas have a different meaning in Matlab.
Post the input data in valid Matlab syntax. Then we can use them by copy&paste.
What is your question?
Berfin Çetinkaya
on 25 May 2022
Jan
on 25 May 2022
Thanks for trying it again. It is no problem for the readers in this forum, if some questions for clarifications are required. This is a typical part of solving a problem.
Let me summarize:
A = [2 1 3; ...
7 1 3; ...
2 8 6; ...
5 9 4];
B = [0.1; 0.7; 0.8];
C = [0.4; 0.1; 0.5];
D = [0.6; 0.5; 0.6];
E = [10; 20; 50];
Berfin Çetinkaya
on 25 May 2022
Jan
on 25 May 2022
I've read your explanations 10 times and they are still confusing. E.g. A is a [4 x 3] matrix and the wanted output is a [3 x 3] matrix only. For "2 1 3" matrix B shoudl be used, but the result contains "0.5, 0.1, 0.8" multiplied elementwise by E([2,1,3]). But "0.5, 0.1, 0.8" is not found in B?!
I cannot imagine, for which kind of problem this code could be a solution.
Berfin Çetinkaya
on 26 May 2022
@Berfin Çetinkaya: Actually the computations should take some lines of code only, but the description is such complicated that my brain is fried. The complexity is growing.
So I recommend to restart from scratch. Avoid talking about "machines" and "products", because for Matlab these are all numbers.
A = [2 1 3; ...
7 1 3; ...
2 8 6; ...
5 9 4];
B = [0.1; 0.7; 0.8];
C = [0.4; 0.1; 0.5];
D = [0.6; 0.5; 0.6];
E = [10; 20; 15];
Most likely it is easier to combine B, C, D to one matrix F = [B,C,D].
Now you want to get:
R = [0.5*20, 0.1*10, 0.8*15; ...
0.7*20, 0.6*10, 0.5*15; ...
0.5*20, 0.6*10, 0.5*15]
According to your explanations, the factors [20, 10, 15] are obtained by:
E(A(1, :));
Does this mean, that the other 3 rows of A do not matter here?
But then I understand your explanations such, that the other factors are taken from B, because the values of the row of A are in the range [1,2,3]. But 0.5 is not an element of B?! So where does the factor 0.5 in the element R(1,1) come from?
Why does R have 3 rows, while A has 4?
Berfin Çetinkaya
on 26 May 2022
Jan
on 26 May 2022
Answers (0)
Categories
Find more on Creating and Concatenating Matrices 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!