필터 지우기
필터 지우기

Computer halts when running Python API functions

조회 수: 2 (최근 30일)
Meme Young
Meme Young 2019년 12월 16일
답변: Meme Young 2019년 12월 16일
I am doing research in power system partition using matpower and results have to be plotted. Matlab is weak in such plotting so I decided to use Python igraph and its API. I have done some little test for its validation like this:
AA=[1 0;0 1;];
import py.igraph.*;
list=py.list([1 2]);
adj=py.numpy.random.randint(0,2);
% AA=py.list(AA);
g=Graph();
g.Adjacency(AA);
The 3rd line is for py.list() test and is not closely relevant. .If it is run as it is,annotated, there will be error report like this:
error in py.igraph.Graph.Adjacency
Python function "Adjacency" cannot accept input at least 1 arguments at postion 1。This function might need you to construct certain dataform from MATLAB arrays.Please refer to documents regarding Python function "Adjacency" and Python arrays.
(Original error report in Chinese since I am using a Chinese version MATLAB.This is translation and might not be that accurate)
If the annotated line is not annotated, the computer will crash(halt) and I have to restart the computer. I really dont know why and would somebody help me use this function corretly?

채택된 답변

Meme Young
Meme Young 2019년 12월 16일
OK it is done. Matlab matrices have to be reshaped then py.list() then py.numpy.reshape() then py.list() to create adjacency matrix for igraph.Adjacency().
AA=[1,0;0,1;];
AA=reshape(AA,1,2*2);
import py.igraph.*;
AA1=py.list(AA);
AA2=py.numpy.reshape(AA1,[int8(2),int8(2)]);
AA3=py.list(AA2);
g=Graph();
g.Adjacency(AA3);
plot(g);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by