How to divide rows in matlab and make into another matrix?

3 Ansichten (letzte 30 Tage)
Violet
Violet am 19 Mai 2016
Bearbeitet: Guillaume am 19 Mai 2016
I am trying to write a program that will divide each row by the sum of the column and place that answer in another matrix.
Here is what I have so far:
toy_identity = eye(3);
a2 = xlsread('Matrix.xlsx', 4, 'B2:D2')
b2 = xlsread('Matrix.xlsx', 4, 'B3:D3')
c2 = xlsread('Matrix.xlsx', 4, 'B4:D4')
Xj = xlsread('Matrix.xlsx', 4, 'B6:D6')
xij = [a2; b2; c2]
toy_A = xij/Xj
toy_f = randi(200, 3, 1);
y = [inv(toy_identity - toy_A)]*toy_f;
the original matrix is:
[ 150 0 100;
20 100 35;
75 65 110]
When I divide it by the sum, it only comes up with
[.37; .18; .34]
where I want it to be a 3x3 matrix Any assistance is much appreciated. Thanks
  1 Kommentar
Violet
Violet am 19 Mai 2016
End goal is to make this into a program that will work for any n x m matrix (i.e. 500x500). I'm assuming I will need to use a for or if function?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

betty bowles
betty bowles am 19 Mai 2016
toy_A = xij/Xj, where xij is a 3x3 matrix and Xj is a 1X3 is attempting to multiply xij by the 'inverse' of Xj, not do what you are wanting. Try slugging it out approach:
toy_A(:,1)=xij(:,1)/Xj(1);
toy_A(:,2)=xij(:,2)/Xj(2);
toy_A(:,3)=xij(:,3)/Xj(3);
  1 Kommentar
Violet
Violet am 19 Mai 2016
That does help, but then when I get to the last line (y = [inv(toy_identity - toy_A)]*toy_f;) it says dimensions still do not match for the "-" operation. How can I make toy_A back into a 3x3?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Import from MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by