Python 함수에서 반환된 데이터 처리하기
Python 유형을 MATLAB 유형으로 자동 변환하기
MATLAB®은 Python® 함수에서 반환된 다음 데이터형을 MATLAB 유형으로 자동 변환합니다.
Python에 표시되는 Python 반환 데이터형 | 결과 MATLAB 유형 — 스칼라 |
---|---|
|
|
| 복소수 |
|
|
datetime |
|
또한 Python에서 MATLAB으로 Python string형 객체를 포함하는 Python 딕셔너리 또는 Python Pandas DataFrame이 반환될 경우, Python string형 객체가 MATLAB string형으로 변환됩니다.
Python 유형을 MATLAB 유형으로 명시적으로 변환하기
다음 MATLAB 함수를 사용하여 Python 데이터형을 MATLAB 유형으로 명시적으로 변환할 수 있습니다.
MATLAB에 표시되는 Python 반환 데이터형 또는 프로토콜 | MATLAB 변환 함수 | 예 |
---|---|---|
|
| MATLAB에서 Python str 변수 사용하기 |
|
| py.help('datetime.date.__str__') Help on wrapper_descriptor in datetime.date: datetime.date.__str__ = __str__(self, /) Return str(self). d = py.datetime.date(...
int32(2020),int32(3),int32(4));
char(d) ans = '2020-3-04' |
|
| |
logical | ||
|
| |
모든 형식의 |
| MATLAB에서 Python 숫자형 변수 사용하기 |
|
| MATLAB에서 Python list 변수 사용하기 |
|
| MATLAB에서 Python 딕셔너리 사용하기 |
py.pandas.DataFrame |
| Use Python Pandas DataFrames in MATLAB |
|
| dt = py.numpy.arange('2022-12-30', ... '2023-01-10',dtype='datetime64[D]'); |
|
| td = py.numpy.array([1,2,3,4], ... dtype='timedelta64[h]'); |
Python 함수의 출력값이 Python 버퍼 프로토콜을 구현하는 유형인 경우(예: numpy.ndarray
), MATLAB에 다음 항목이 표시됩니다.
실제 Python 유형
기본 데이터
해당하는 MATLAB 변환 함수. 이 함수를 사용하여 Python 객체를 MATLAB 배열로 완전히 변환할 수 있습니다.
예를 들어, Python 함수는 다음 배열 p
를 반환합니다.
p = Python ndarray: 8 1 6 3 5 7 4 9 2 Use details function to view the properties of the Python object. Use double function to convert to a MATLAB array.
제안된 변환 함수를 사용하여 p
를 MATLAB 행렬 P
로 변환합니다.
P = double(p)
P = 3×3 8 1 6 3 5 7 4 9 2
p
의 Python 속성에 대한 구체적인 정보를 확인합니다.
details(p)
py.numpy.ndarray handle 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[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×2 py.tuple] size: [1×1 py.int] strides: [1×2 py.tuple] Methods, Events, Superclasses
Python 모듈이 __doc__
특성의 콘텐츠를 제공하는 경우, MATLAB은 이 정보로 연결됩니다.