0

I am a beginner in MATLAB.

I have a function that takes an integer as input and returns a directed graph (digraph); I therefore have a list of integers L, and would like to create a list of digraphs derived from such integers.

I have a function create_graph(n) that returns such digraph.

What I am currently doing is:

Gs = [];
for i=1:length(L)
   x = L(i);
   G = create_graph(x);
   Gs(end + 1) = G;
end

And it returns an error:

Unable to perform assignment because value of type 'digraph' is not convertible to 'double'.

Error in dummy_code (line 20)
    Gs(end + 1) = G;

Caused by:
    Error using double
    Conversion to double from digraph is not possible.

Another error appear if I initialize a dummy digraph, that is:

Gs = [digraph([1,1;1,1])];
for i=1:length(L)
   x = L(i);
   G = create_graph(x);
   Gs(end + 1) = G;
end
Error using indexing
Unsupported graph indexing.
 

What I would like to do is something close to the python code:

Gs = [create_graph(x) for x in L]
vevvostar
  • 135
  • 8
  • 1
    set `Gs = {}; ...; Gs(end + 1) = {G};` to make `Gs` a cell array of digraphs. – rahnema1 Feb 06 '23 at 18:07
  • Each item in a Python list can be any type of Python object. Each item in a MATLAB matrix or vector must be a numeric value. The nearest MATLAB equivalent to a Python list is a cell array. – nekomatic Feb 13 '23 at 23:28

0 Answers0