# How to solve this problem " The specified superclass 'CyclicLatticeTopology' contains a parse error"?

12 views (last 30 days)
Rayan Glus on 10 Oct 2021
Commented: Rayan Glus on 10 Oct 2021
I get this error whenever I try to run the following code which I found on FileExchange:
The specified superclass 'CyclicLatticeTopology' contains a parse error, cannot be found on MATLAB's search path, or is shadowed by another file with the same name.
% SmallWorldTopology - Small world topology
% This is a small world network topology, i.e., a graph with a very low
% diameter despite a relatively low mean degree of the nodes. This is
% constructed using the so-called Watts-Strogatz mechanism:
%
% 1) A cyclic lattice is constructed, with K/2 neighbors for each
% node.
% 2) Every connection is randomly rewired with probability 'beta'.
%
% Initialize it with the K and beta parameters:
%
% t = SmallWorldTopology(N, K, beta);
classdef SmallWorldTopology < CyclicLatticeTopology
properties
beta;
end
methods
function obj = SmallWorldTopology(N, K, beta)
obj = obj@CyclicLatticeTopology(N, K);
assert(isinrange(beta), 'Lynx:Runtime:Validation', 'The beta parameter of SmallWorldTopology must be in [0, 1]');
obj.beta = beta;
end
function obj = construct(obj)
obj = obj.construct@CyclicLatticeTopology();
for i = 1:obj.N
neighbors = obj.getNeighbors(i);
dice = rand(length(neighbors), 1) < obj.beta;
toBeRewired = neighbors(dice);
for j = 1:length(toBeRewired)
newNeighbor = randi(obj.N, 1);
obj.W(i, toBeRewired(j)) = 0;
obj.W(toBeRewired(j), i) = 0;
obj.W(i, newNeighbor) = 1;
obj.W(newNeighbor, i) = 1;
end
end
obj.W(logical(eye(obj.N))) = 0;
end
function s = getDescription(obj)
s = sprintf('Small world network');
end
end
end
Note: I use MATLAB 2018a
Thanks!
##### 2 CommentsShowHide 1 older comment
Rayan Glus on 10 Oct 2021
I just did and it worked. Thank you so much.
Unfortunately, when I run this code, the adjacency matrix was full of zeros.