Running python code and packages in MATLAB

51 Views Asked by At

I am trying to run a python package in MATLAB. I tried to run it throuhg Anaconda, by that I mean I opened a ".m" file in my MATLAB folder through the anaconda prompt, wrote some code on the file and then saved, then I opened this ".m" file on MATLAB and tried running it but I keep getting the error message of "Unable to resolve the name 'py.gekko.GEKKO'.", the third line of code. I've tried with other similar python code and an error always comes up the first time any python code is called, so I think MATLAB is just not recognizing the python code. I have even checked in anaconda if this package, called GEKKO, is installed, and it is. Any ideas?

This was the python code in the ".m" file I was trying to run

% start Matlab from Anaconda prompt
close all; clear;
% Solve linear equations
% Initialize Model
m = py.gekko.GEKKO();    <----- error occurs here
% Initialize Variables
x = m.Var();            % define new variable
y = m.Var();            % default=0
% Define Equations
m.Equation(3*x+2*y==1);
m.Equation(x+2*y==0);  
% Solve
m.solve();
% Extract values from Python lists using curly brackets
disp(['x: ' num2str(x.VALUE{1})]);
disp(['y: ' num2str(y.VALUE{1})]);
0

There are 0 best solutions below