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?
How to divide rows in matlab and make into another matrix?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
Antworten (1)
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);
Siehe auch
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!