Hello, I am trying to compute the mean of a Python numeric vector in MATLAB. To clarify, I am using Python but am trying to rely on some MATLAB-specific functions by running MATLAB in a Python environment. I am using matlab.engine to do this:
import numpy as np
!pip install matlab
eng = matlab.engine.start_matlab()
data = np.arange(5)
data_list = data.tolist()
eng.workspace['foo'] = data_list
I keep encountering the following error at the last line:
"File /Applications/MATLAB_R2018b.app/toolbox/matlab/datafun/mean.m, line 127, in mean Invalid data type. First argument must be numeric or logical."
To my understanding, this is owing to MATLAB somehow not recognizing the type of objects stored in data_list when data_list is being ported over to the engine workspace (as foo). I've tried (1) specifying the dtype when creating the object data, and (2) removing data.tolist() and porting data over directly, but both methods do not fix the issue. (Method 2 produces another error, "TypeError: unsupported Python data type: numpy.ndarray".)
Could anyone here help to troubleshoot? Thanks in advance!