0

I am writing code in Matlab.

A matrix:

[2    1     4     3;...
10   15    20    10;...
20   10    15    20];

B matrix:

[1    3   4;..   
 4    5   6;... 
 2    1   4;...
 3    5   1];

C matrix:

[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?

2
  • Can you edit the question to show the composition of each number in your desired output? At the minute it's not clear to me how each value is generated, e.g. 400=B(2,1)*C(2) - this would rule out any ambiguity in your description
    – Wolfie
    May 27, 2022 at 8:15
  • The question is unclear (or at least, my interpretation does not match the suggested output), but a first pass answer would be something like this: for ii = 1:2; for jj = 1:4; D(ii, jj) = B( A(1,jj), A(ii+1,jj)/5-1 ) * C( A(1,jj) ); end; end;. If the question can be clarified this would ideally be done without loops.
    – magnesium
    May 28, 2022 at 7:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.