フィルターのクリア

How can transfer python result to Matlab matrix

122 ビュー (過去 30 日間)
KOU DU
KOU DU 2019 年 4 月 3 日
コメント済み: KOU DU 2020 年 2 月 19 日
I use 'system' to import a python coding and got the result as show below:
G=
Python ndarray with properties:
T: [1×1 py.numpy.ndarray]
base: [1×1 py.NoneType]
ctypes: [1×1 py.numpy.core._internal._ctypes]
data: [1×3 py.memoryview]
dtype: [1×1 py.numpy.dtype]
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×2 py.tuple]
size: [1×1 py.int]
strides: [1×2 py.tuple]
[[1.00000001 1.00000001 3.00000001]
[1.00000001 1.00000001 3.00000001]
[1.00000001 1.00000001 3.00000001]]
How Can I transfer the data of G in format of Matlab matrix ?
  1 件のコメント
KOU DU
KOU DU 2019 年 4 月 10 日
I have solved this question in general case. Thank you!

サインインしてコメントする。

回答 (2 件)

Agnish Dutta
Agnish Dutta 2019 年 4 月 10 日
You need to save this array in a format that MATLAB understands. You could use scipy.io to do this.
As an example:
import numpy as np
import scipy.io
x = np.linspace(0, 2 * np.pi, 100)
y = np.cos(x)
scipy.io.savemat('test.mat', dict(x=x, y=y))
You can then load this in matlab with "load". Refer to the following for more information:
  1 件のコメント
KOU DU
KOU DU 2019 年 4 月 10 日
Thank you Agnish, I have found a way to transfer directly in matlab.

サインインしてコメントする。


Aim Newb
Aim Newb 2020 年 2 月 18 日
May you please inform about the way you transfer the results directly to matlab?
I'm having the same problem.
  1 件のコメント
KOU DU
KOU DU 2020 年 2 月 19 日
For example, In Matlab
A_Array=py.numpy.array(B) % B is the data which you got from python, A is in array format
A_matrix=nparray2mat(A_Array); %change python array to matlab matrix
you can find nparray2mat in this answer:
fr.mathworks.com/matlabcentral/answers/157347-convert-python-numpy-array-to-double

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by