Effacer les filtres
Effacer les filtres

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

19 vues (au cours des 30 derniers jours)
karthikeyan Reddy Thoomu
karthikeyan Reddy Thoomu le 28 Juil 2017
Commenté : Walter Roberson le 29 Juil 2017
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')

Réponse acceptée

Walter Roberson
Walter Roberson le 28 Juil 2017
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 commentaires
karthikeyan Reddy Thoomu
karthikeyan Reddy Thoomu le 28 Juil 2017
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 le 29 Juil 2017
You need a 6th column for your 6th node

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by