matrix component algebra with digraph

조회 수: 3 (최근 30일)
Connor McGrath
Connor McGrath 2020년 8월 1일
답변: Steven Lord 2020년 8월 3일
Hi everyone,
I dont have much experience with matlab so bear with me. I'm working on a project where I create a random binary nxn matrix to serve as a adjacent matrix for a digraph. I'm stuck on the part where I need to create the transition matrix from the following equation: M=Mij=(Aij/Cj). With ij being the psoition of each individual component and Cj being the outdegree of node j (which I know I can find with the outdegree functon). For example component M11 in matrix M would be calculated as follows: M11=(A11/C1). I beleive I need to use a for loop in order to calculate each component as shown of the M matrix but am not sure how to tackle it. Any help would be appreciated!

답변 (2개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 8월 2일
편집: KALYAN ACHARJYA 2020년 8월 3일
[row,col]=size(A);
%Expecting C is 1 D vector and having col number of rows minimum
M=zeros(row,col);
for i=1:row
for j=1:col
M(i,j)=A(i,j)/C(j);
end
end
M
  댓글 수: 2
Connor McGrath
Connor McGrath 2020년 8월 2일
Thanks for the help, I howver get this error when attempting to run it however:
KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 8월 3일
There was minor mistake, corrected
M=zeros(row,col);
%^ i, j removed ..copy ^this line

댓글을 달려면 로그인하십시오.


Steven Lord
Steven Lord 2020년 8월 3일
R = randi([0 1], 10)
D = digraph(R);
OD = outdegree(D)
R./OD
Be careful of the case where one or more of the nodes has outdegree 0.

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by