1
$\begingroup$

I am testing to call a Scipy function of Decimate from Matlab and get a ndarray from this function with structure as below

y_data =

Python ndarray with properties:

   T: [1×1 py.numpy.ndarray]
    base: [1×1 py.numpy.ndarray]
  ctypes: [1×1 py.numpy.core._internal._ctypes]
    data: [1×61 py.memoryview]
   dtype: [1×1 py.numpy.dtype[float64]]
   flags: [1×1 py.numpy.flagsobj]
    flat: [1×1 py.numpy.flatiter]
    imag: [1×1 py.numpy.ndarray]
itemsize: [1×1 py.int]
  nbytes: [1×1 py.int]
    ndim: [1×1 py.int]
    real: [1×1 py.numpy.ndarray]
   shape: [1×1 py.tuple]
    size: [1×1 py.int]
 strides: [1×1 py.tuple]

[ 5.99081382e-03  5.83549240e-01  9.51130546e-01  9.48473537e-01
  5.86508837e-01  1.02585620e-03 -5.88140511e-01 -9.47959932e-01
 -9.50266816e-01 -5.86279197e-01  5.24797354e-05  5.86330487e-01
  9.49823174e-01  9.48834128e-01  5.87047010e-01 -1.59869334e-04
 -5.86712088e-01 -9.49194165e-01 -9.49481760e-01 -5.86544283e-01
 -1.19347373e-04  5.86767698e-01  9.49307038e-01  9.49280786e-01
  5.86755373e-01 -4.55924399e-05 -5.86674972e-01 -9.49330026e-01
 -9.49305409e-01 -5.86712712e-01  1.02337656e-05  5.86690123e-01
  9.49332521e-01  9.49300839e-01  5.86697807e-01  4.20505327e-05
 -5.86784485e-01 -9.49211137e-01 -9.49413536e-01 -5.86643745e-01
  1.30050483e-05  5.86588130e-01  9.49543168e-01  9.49003229e-01
  5.87021587e-01 -2.10799396e-04 -5.86717779e-01 -9.48992721e-01
 -9.49956824e-01 -5.85832688e-01 -8.98924013e-04  5.87341478e-01
  9.49239365e-01  9.48646598e-01  5.88253289e-01 -2.43631403e-03
 -5.83370405e-01 -9.52366021e-01 -9.49453473e-01 -5.88127079e-01
 -1.23584431e-02]

How to convert this structure into Matlab format? Or simply put the data into a Matlab array? Thanks in advance.

I have tried to use Matlab command

double, struct, evalc ([' disp(y_data) '])

without success.

$\endgroup$
2
  • $\begingroup$ Why don't just start with a simple function where you already know the result? Somethin like mean() $\endgroup$
    – Hilmar
    Commented May 8 at 15:26
  • $\begingroup$ Please don’t double-post! stackoverflow.com/q/78448120/7328782 $\endgroup$ Commented May 9 at 18:49

1 Answer 1

1
$\begingroup$

This isn't a signal processing question, so might be outside the scope of acceptable questions. I'll let the mods decide.

Two ways depending on your Matlab version and setup:

y_data_matlab = double(py.array.array('d', py.numpy.nditer(y_data)));

Or

y_data_matlab = double(py.numpy.asarray(y_data));
$\endgroup$
1
  • $\begingroup$ Thanks, Jdip. the first line of command works in my version of Matlab 2020a. $\endgroup$
    – ZhangJ
    Commented May 9 at 7:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.