'matlab.object' object is not callable using matlab engine

209 Views Asked by At

I am trying to use MATLAB engine from Python as follows

sinewave = eng.dsp.SineWave("Amplitude",1,"Frequency",fc,"SampleRate",fs,"SamplesPerFrame",nspf,"ComplexOutput",True)
sinewave()

to use the DSP toolbox. However, I get the error "'matlab.object' object is not callable for sinewave()". Doing the same, directly in MATLAB (without the eng.) works just fine. What is the correct way for calling sinewave from Python?

1

There are 1 best solutions below

0
Tommy Wolfheart On BEST ANSWER

Ok got it.

For anyone that's looking, once you get your object, add it to your workspace and then call the workspace variable using eval. In this case, this would be

sinewave = eng.dsp.SineWave("Amplitude",1,"Frequency",fc,"SampleRate",fs,"SamplesPerFrame",nspf,"ComplexOutput",True)
eng.workspace['sinewave'] = sinewave
x = eng.eval('sinewave()')

And then since in MATLAB, my x would have been a vector, in Python, my x is a Python list and I can print the first element using x[0] or whatever I want to do. I can also add x into the workspace and keep working like that.