Mixing two matrices according to one variable. Need help!

I need to mix two matrices according to one variable, which will determine the weight to assign to each matrix. The problem is that the program will have also to find in each of the two matrices the rows which have the same value for the indicator variable (and this does not happen usually in the same row, ie: in matrix A I have value 100 for the indicator variable in row 8 and in matrix B I have it in row 10 - i will then have to mix these two rows according to the values present in another column).

In order to make it more clear, I upload an attachment with matrices A, B and C as a zipped .mat file

the indicator variable is the one present in column 8, ie I have to take from matrix A and matrix B all the couples of rows which have the same indicator variable.
Once I have done this, I have to mix these couple of rows in the following way: the weighted sum of them must be such that the new row will have a 30 in column 7, ie weight= (30-B(1,7))/(A(1,7)/B(1,7)) and
thus
newrow=weight*B(nrselectrowforb,:)+(1-weight)*A(nrselectrowfora,:)

and I have to do this for all combinations of rows where A and B have the same indicator variable.

Moreover, this will have to go in an IF clause where:

if I have both A and B for a specific indicator variable, then use the mix as specified above.
if I have both A and C for a specific indicator variable, then use the mix as specified above.
if I have both B and C for a specific indicator variable, then use the mix as specified above.
if I have only A, then do weight=30/A(1,7) and newrow=weight*A(nrselectrowfora,:)
if I have only B, then do weight=30/B(1,7) and newrow=weight*B(nrselectrowforb,:)
if I have only C, then do weight=30/C(1,7) and newrow=weight*C(nrselectrowforc,:)

Can someone help me on this one? I am trying all sorts of things, like using "find" and putting it inside a loop or using complex if structures but I came to no conclusion.

thanks a lot

Comments

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion