在Matlab中将ndarray转换为结构体

问题描述 投票:0回答:1

我正在测试从 Matlab 调用 Decimate 的 Scipy 函数,并从该函数中获取结构如下的 ndarray

y_数据=

Python ndarray 具有属性:

       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]

如何将该结构转换为Matlab格式?或者只是将数据放入Matlab数组中? 预先感谢。

我尝试过使用Matlab命令

double, struct, evalc ([' disp(y_data) '])
matlab multidimensional-array scipy type-conversion dataformat
1个回答
0
投票

感谢 Nick 和 hpaulj 的评论。对于有相同问题的人,我找到了如下的解决方案 double(py.numpy.asarray(y_data)))

© www.soinside.com 2019 - 2024. All rights reserved.