필터 지우기
필터 지우기

How to fix the error 'Adjacency matrix must be square'?

조회 수: 19 (최근 30일)
karthikeyan Reddy Thoomu
karthikeyan Reddy Thoomu 2017년 7월 28일
댓글: Walter Roberson 2017년 7월 29일
I was working with following code to plot and it shows the error 'Adjacency matrix must be square'
clear all
close all
clc
K=[0 0 0 0 1 , 0 0 0 0 2 , 0 0 0 0 3, 0 0 0 0 4 , 0 0 0 0 5 , 0 0 0 0 0];
nodes= ['A', 'B' , 'C' , 'D' , 'E' , 'F'];
G = digraph(K,nodes);
plot(G,'Layout','circle')
title('STAR TOPOLOGY')

채택된 답변

Walter Roberson
Walter Roberson 2017년 7월 28일
In your assignment to K, change the commas into semi-colon
K=[0 0 0 0 1 ; 0 0 0 0 2 ; 0 0 0 0 3; 0 0 0 0 4 ; 0 0 0 0 5 ; 0 0 0 0 0];
  댓글 수: 2
karthikeyan Reddy Thoomu
karthikeyan Reddy Thoomu 2017년 7월 28일
Thank you so much Walter Roberson for answering. when i tried with semicolon and run the code it shows as same error Adjacency matrix must be square, then i tried using (.^2) operator in the code as shown below clear all close all clc K=[0 0 0 0 1 ; 0 0 0 0 2 ; 0 0 0 0 3 ; 0 0 0 0 4 ; 0 0 0 0 5 ; 0 0 0 0 0]; nodes= ['A', 'B' , 'C' , 'D' , 'E' , 'F']; G = digraph(K,nodes.^2); plot(G,'Layout','circle') title('STAR TOPOLOGY')
when i run this code it shows the error as follows Error in digraph (line 247) matlab.internal.graph.constructFromEdgeList( ... How to fix it?...
Walter Roberson
Walter Roberson 2017년 7월 29일
You need a 6th column for your 6th node

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by