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

19 次查看(过去 30 天)
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
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?...

请先登录,再进行评论。

更多回答(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