problem in neighbors function

hello,
This is my graph
G=[0 1 1 0 0 0;1 0 1 1 0 0; 1 0 0 1 1 0; 0 0 0 0 1 0; 0 0 0 0 0 1; 0 1 0 1 1 0];
when I apply the function neighbors
neighbors(G,active_nodes_last_round(individual));
where active_nodes_last_round(individual)=1;
I got the following error:
Undefined function 'neighbors' for input arguments of
type 'double'.
Error in IC_paper1 (line 26)
potential_infected=neighbors(G_duplicate,active_nodes_last_round(individual));
Thanks in advance

Antworten (1)

Steven Lord
Steven Lord am 27 Jul. 2022

0 Stimmen

The neighbors function, in this context, requires its first input to be a graph object not an adjacency matrix. Create a graph object from your adjacency matrix by calling graph and pass the resulting object into neighbors.

13 Kommentare

huda nawaf
huda nawaf am 27 Jul. 2022
Bearbeitet: huda nawaf am 27 Jul. 2022
thank u
what I did
G = graph(A)
where A is adjacancy matrix, but the problem is still:
Undefined function 'graph' for input arguments of type
'double'.
I think it is not found in ver. R2013a
The graph object was introduced in release R2015b (as was the neighbors function.)
Are you using an earlier release?
If you're using release R2015b or later, what do these two commands display?
which -all graph
which -all neighbors
huda nawaf
huda nawaf am 27 Jul. 2022
I did
It is not found
thanks
Don't tell me what they displayed. Show me. Please copy and paste the exact output you see from those two commands into a comment. Also show me what release you're using (copying and pasting the output from the following call would be an easy way to do so.)
version
huda nawaf
huda nawaf am 27 Jul. 2022
'graph' not found.
C:\Program Files\MATLAB\R2013a\toolbox\matlab\polyfun\@triangulation\neighbors.m % triangulation method
C:\Program Files\MATLAB\R2013a\toolbox\matlab\polyfun\@TriRep\neighbors.m % TriRep method
I used R2013a
Steven Lord
Steven Lord am 27 Jul. 2022
You won't be able to use any of the graph and network algorithm functionality included in MATLAB as of release R2015b (including the neighbors function for graph objects.) You're using an older release of MATLAB. You would need to upgrade to release R2015b or later.
huda nawaf
huda nawaf am 28 Jul. 2022
Thanks
huda nawaf
huda nawaf am 30 Jul. 2022
thanks,
Do u mean I should download this toolbox in my old version, then I can use the function of neighbors and all functions related to graphs?
Walter Roberson
Walter Roberson am 31 Jul. 2022
No. Those toolboxes are not exact replacements for the MATLAB graph functions.
The idea is that possibly you could rewrite whatever algorithm you are trying to do, in terms of the functions provided by one of those toolboxes.
If you need drop-in replacements for neighbors() and the other MATLAB graph-theory functions, then you should upgrade your MATLAB to at least R2015b.
huda nawaf
huda nawaf am 1 Aug. 2022
I'm trying to install matlab R2015b or newer. Because when I install Matlab every time I go to fake links that contain ads.
Can anyone forward to me a trusted link?
Steven Lord
Steven Lord am 1 Aug. 2022
If you've purchased a license for the later releases you should have received instructions on how to download and install it in an email from Mathworks. Or you could go to the "Download Products" section on the Support section of the website, or you could click on the Get MATLAB button in the upper-right corner of this page.
huda nawaf
huda nawaf am 2 Aug. 2022
Bearbeitet: huda nawaf am 2 Aug. 2022
thanks @ steven
I installed trail ver. , and I run the code.
I created adjacancy mat. and call graph, then run code without any problem.
In fact the code is existing in a paper, it is working but the results are not satisfied.

Melden Sie sich an, um zu kommentieren.

Kategorien

Produkte

Version

R2013a

Gefragt:

am 27 Jul. 2022

Bearbeitet:

am 2 Aug. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by