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

3 ビュー (過去 30 日間)
Violet
Violet 2016 年 5 月 19 日
編集済み: Guillaume 2016 年 5 月 19 日
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 件のコメント
Violet
Violet 2016 年 5 月 19 日
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?

サインインしてコメントする。

回答 (1 件)

betty bowles
betty bowles 2016 年 5 月 19 日
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 件のコメント
Violet
Violet 2016 年 5 月 19 日
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?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by