0

I'm using oct2py to call a octave function in my python code. Everything should be OK, and the octave function exectuted with octave works but when I call the function with python I have this error:

import os

pathToExecutable = ('C:\\Octave\\Octave-5.2.0\\mingw64\\bin\\octave-cli.exe')
os.environ['OCTAVE_EXECUTABLE'] = pathToExecutable

from oct2py import octave
import pprint
import numpy as np
import matplotlib.pyplot as plt
from scipy.io import loadmat

octave.addpath(octave.genpath('E:/funcs/software/octave_calls'))
octave.eval('MSPP')

Oct2PyError: Octave evaluation error: error: 'AvgPwr' undefined near line 22 column 15 error: called from: MSPP at line 22, column 8

The octave code in this line is the next:

Power=AvgPwr

When AvgPower is defined when I import it from a .mat file with

load params.mat %<--transcription corrected (before it was load(params.mat)

EDIT:

First lines of MSSP.

warning off
close all;
clear all;
clc;

%% Load pameters

load params.mat
  
################################################################################

%% CW Laser

Plaser = 10^((AvgPwr-30)/10);         % Average Laser Power
emzm = 1.0;

params.mat is generated in another octave file where I load all parameters and it contains the variable AvgPwr, I think it's everything correct with the octave code because it works well when I use octave to run it.

  • Are you absolutely sure that you are accessing the correct params.mat file, that your octave instance starts at the directory that you think it does, and that the AvgPwr variable is indeed stored in that .mat file? And that it has been placed in the base octave workspace? (`octave.eval('whos')`). Also, sometimes it;s better to do things via the `octave.eval("addpath...` route rather than the `octave.addpath(...` one. Also pointing out that `load(params.mat)` attempts to load the string stored in the mat field of a struct named 'params'. You probably want `load('params.mat')` instead. – Tasos Papastylianou Nov 06 '20 at 13:46
  • Yeah: can you post the first 30 or so lines of `MSPP.m` so we can have some more context about what's going on here? – Andrew Janke Nov 12 '20 at 06:44
  • Hi! Thanks both for the comments. I edited the code with more info. I had a mistake writing the load(params.mat), actually it was load params.mat. I tried with load('params.mat') but still the same error. – David Moreno Nov 12 '20 at 12:16

0 Answers0