Saving a graph with edges and nodes

1 回表示 (過去 30 日間)
Deepa Maheshvare
Deepa Maheshvare 2019 年 9 月 7 日
コメント済み: Stephan 2019 年 9 月 9 日
Hi All,
I have the following graph with nodes and edges. This graph is creadted in a function defined in file create.m. Can this graph be stored and access in
another file , another.m (for instance, I'd like to assign weights to the edges of the graph in another file)?
I understand I can call the function defined in create.m from another.m. However, I don't want to do this. Instead, I prefer saving the graph object and accessing it in other
files.
NNode = 11;
tail = 1:NNode-1;
head = 2:NNode;
Graph = graph(tail,head);
plot(Graph);

採用された回答

Stephan
Stephan 2019 年 9 月 7 日
編集済み: Stephan 2019 年 9 月 7 日
You can not save a workspace object in a .m-file. Use a .mat-file instead to save your graph. You can load this in other scripts to work with.
  2 件のコメント
Deepa Maheshvare
Deepa Maheshvare 2019 年 9 月 7 日
Thanks a lot for the response.
I did try using .mat
save('Graph.mat', 'Graph')
>> Graph = load('Graph.mat')
Graph =
struct with fields:
Graph: [1×1 graph]
I could access the nodes and edges properties using
>> height(Graph.Graph.Edges).
However, when
save('Graph.mat', '-struct', 'Graph')
is used, I get the following error
Error using save
The argument to -STRUCT must be the name of a scalar structure variable.
Error in create_graph (line 14)
save('Graph.mat', '-struct', 'Graph')
Stephan
Stephan 2019 年 9 月 9 日
Note that a graph object is not a struct - thus you can not do it this way.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by