필터 지우기
필터 지우기

Convert Python list Type to MATLAB double

조회 수: 62 (최근 30일)
SAI KRISHNA CHADA
SAI KRISHNA CHADA 2021년 12월 2일
댓글: Kent Schonert 2024년 4월 23일
Hello All,
I would like to convert the python list type to matlab double.
I have tried the following,
First approach
out = func.getValues() %python function gives a list of [1,2,...n]
out = cell(out(1:end-1));
out = cellfun(@double,out); %outputs type double
Second approach
out = func.getValues() %python function gives a list of [1,2,...n]
out = func.convlisttoarray(out) %python function imports numpy and converts list to array using numpy.array()
out_double = double(out); % outputs type double
Although the length of the list is 1x150, in both the approaches, Matlab is taking a lot of computation time and the system hangs for a while. This is wierd to me, as a couple of days earlier everything worked fine and it could solve the problem in milli seconds.
Could anyone of you please help me with a faster approach to convert the python list to matlab double?
I am using Matlab 2019b.
Thank you in advance.
Cheers,
Sai Krishna

답변 (1개)

Sean de Wolski
Sean de Wolski 2021년 12월 2일
q = py.list({1,2,3})
q =
Python list with no properties. [1.0, 2.0, 3.0]
cq = cell(q)
cq = 1×3 cell array
{[1]} {[2]} {[3]}
[cq{:}]
ans = 1×3
1 2 3
  댓글 수: 3
Sean de Wolski
Sean de Wolski 2022년 7월 18일
Do you have python installed and configured? I.e. what's the output of
pyenv
ans =
PythonEnvironment with properties: Version: "2.7" Executable: "/usr/bin/python" Library: "libpython2.7.so.1.0" Home: "/usr" Status: NotLoaded ExecutionMode: InProcess
It should not be empty.
Kent Schonert
Kent Schonert 2024년 4월 23일
I'm also using 2019b and cannot figure out how to convert python lists to matlab array.
q = py.list({1,2,3})
cq = cell(q) %errors out in 2019b . . .
Error using cell
Conversion to cell from py.list is not possible.
Later versions of Matlab support this, but not 2019b and below, which I (and my workgroup) am stuck using.

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

카테고리

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