Call poly2trellis in Python

조회 수: 4 (최근 30일)
blue_sdr
blue_sdr 2017년 2월 23일
댓글: blue_sdr 2017년 2월 27일
Hi!
I want to call 'poly2trellis' from Python:
my_trellis = eng.poly2trellis(7, [133, 171])
This results in the following error:
Error using commstr2poly (line 180) Input must be a character vector or a cell of character vectors.
Error in poly2trellis (line 42) cellOutput = commstr2poly(codeGenerator, 'octal');
Thus, I did
function [ trellis ] = get_trellis( )
trellis = poly2trellis(7, [133 171]);
end
It works with all I want to do, but obviously I lost the ability to parameterize it. This is my next approach:
function [ trellis ] = get_trellis( L_C )
trellis = poly2trellis(L_C, [133 171]);
end
This is called in Python with:
eng.get_trellis(7)
And it stops working with:
Error using poly2trellis_mex Input arguments must be nonempty real matrices.
Error in poly2trellis (line 51) trellis = poly2trellis_mex(varargin{:});
Error in get_trellis (line 4) trellis = poly2trellis(L_C, [133 171]);
The same function works if I call it in Matlab directly, but here I need MEfP, so this is not an option. Furthermore, I want to call 'poly2trellis' directly.
Any ideas how to make this work?
Thanks!

채택된 답변

Bo Li
Bo Li 2017년 2월 27일
You need to use mlArray in order to pass an array to MATLAB from Python. A Python list is converted into a MATLAB Cell array which is not accepted by "poly2trellis". Try this:
>>> eng.poly2trellis(7.0, matlab.double([133,171]))
Reference:
  댓글 수: 1
blue_sdr
blue_sdr 2017년 2월 27일
Thanks! It works!

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

추가 답변 (3개)

Image Analyst
Image Analyst 2017년 2월 23일
It seems to be saying you called it without passing in anything for L_C
trellis = get_trellis();
Is that what you did? If so you'll need to pass in 7 or something
trellis = get_trellis(7);
  댓글 수: 1
blue_sdr
blue_sdr 2017년 2월 24일
I started with the first version without any arguments. This version works. But the second version with one argument does not work. It does not fail because of a missing argument, but because
Error in get_trellis (line 4) trellis = poly2trellis(L_C, [133 171]);
and I called it with
eng.get_trellis(7)
Also, it works in Matlab, but the MEfP call fails.

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


Bo Li
Bo Li 2017년 2월 24일
How about trying following:
>>>eng.get_trellis(7.0)
It looks that the poly2trellis expects the first argument to be a double, but Python Engine convert 7 to int64:
In MATLAB, a number is by default "double" type. If you do following in MATLAB, you can the see the same error:
>> trellis = poly2trellis(int64(7), [133 171]);
Error using poly2trellis_mex
Input arguments must be nonempty real matrices.
Error in poly2trellis (line 51)
trellis = poly2trellis_mex(varargin{:});

blue_sdr
blue_sdr 2017년 2월 27일
Thanks for the suggestions so far.
I modified my code
function [ trellis ] = get_trellis( lc )
lc = double(lc);
poly = [133 171];
trellis = poly2trellis(lc, poly);
end
Now, in MEfP, the call 'eng.get_trellis(7)' works.
Further, I want to 'poly' to be a parameter. I modified my function like this:
function [ trellis ] = get_trellis( lc, poly )
lc = double(lc);
if iscell(poly)
poly = cell2mat(poly);
poly = double(poly);
end
trellis = poly2trellis(lc, poly);
end
Now, this works too. with 'eng.get_trellis(7, [133, 171])'. This is something that really surprises me, because I tested it before and it failed on me.
Finally, I want to call 'poly2trellis' directly.
eng.poly2trellis(7.0, [133.0, 171.0])
This last one does not work. The error messages is as follows.
Error using commstr2poly (line 180) Input must be a character vector or a cell of character vectors.
Error in poly2trellis (line 42) cellOutput = commstr2poly(codeGenerator, 'octal');
How can I make the last call to 'poly2trellis' work?

카테고리

Help CenterFile Exchange에서 Error Detection and Correction에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by