필터 지우기
필터 지우기

convert python code to MATLAB

조회 수: 2 (최근 30일)
Yasyfa Rifiani Putri
Yasyfa Rifiani Putri 2021년 11월 6일
편집: Chris 2021년 11월 7일
Hi, everyone! I need a help to convert python code to matlab about mie scattering in homogenous sphere, below is my python code. I add 'z' variable to get the value of scattering.
import PyMieScatt as ps
mie = ps.MieQ(1.525+0.0011j,450,300,asDict=True) %index refractive, wavelength, diameter of particle
z = mie['Qsca']
  댓글 수: 2
Chris
Chris 2021년 11월 6일
PyMieScatt is not a trivial program. If you want something similar to use in native Matlab, you will probably have to find an implementation somewhere else, or write your own. If you want to try using python from Matlab, you can follow the below steps (but Matlab freezes for me when I try this).
  1. Have a supported version of python installed: CPython 2.7, 3.7, 3.8, or 3.9
  2. In Matlab, set it up with pyenv, e.g.: pyenv('Version','path/to/supportedVersion')
  3. Run (do not import):
mie = py.PyMieScatt.MieQ(1.525+0.0011j,450,300,asDict=True);
Further information:
Cris LaPierre
Cris LaPierre 2021년 11월 7일
Admitting that I know nothing about this topic, a keyword search indicates this file exchange submission might be of interest.

댓글을 달려면 로그인하십시오.

답변 (1개)

Chris
Chris 2021년 11월 7일
편집: Chris 2021년 11월 7일
With Mie.py in your Matlab path and pyenv set up correctly, do:
mie = struct(py.Mie.MieQ(1.525+0.0011j,450,300,pyargs('asDict',true)))
z = mie.Qsca

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by