Error - 'All inputs must be constant' in MATLAB Coder

I am trying to convert the function poly2trellis into C using MATLAB Coder. The problem arise when I check the issues in the Coder App and it displays the error that ' all inputs must be constant'.
function [ trellis ] = con_poly2trellis(k) %#codegen
generator_matrix=[0 0];
if k==3
generator_matrix=[5 7];
else
generator_matrix=[32 35];
end
trellis = poly2trellis(k,generator_matrix);
end
Does it mean that I can generate code for a single specific input and not based on any value passed for 'k'?
What if a generic function is required which can accept any value of 'k' and I can include multiple if-else case for generator_matrix?
Please help and suggest.

 채택된 답변

Walter Roberson
Walter Roberson 2017년 12월 26일
if k==3
trellis = poly2trellis(3,[5,7]);
elseif k==4
And so on.

댓글 수: 5

Thanks for the answer. I tried this and checked for the input k=4. But it is now producing error at k=3 Generator describes code of less than specified constraint length.
The coder checks each and every mention of the poly2trellis function for all the cases irrespective of input provided.
if K==2
trellis = poly2trellis(2,[0 0]);
elseif K==3
trellis = poly2trellis(3,[5 7]);
elseif K==4
trellis = poly2trellis(4,[15 17]);
elseif K==5
trellis = poly2trellis(5,[32 35]);
elseif K==6
trellis = poly2trellis(5,[53 75]);
elseif K==7
trellis = poly2trellis(7,[133 171]);
elseif K==8
trellis = poly2trellis(8,[247 371]);
elseif K==9
trellis = poly2trellis(9,[1167 1545]);
end
The coder checks for each if else and produces error. I even tried switch case.
Yes the above link clarifies the usage of poly2trellis. But how to resolve the conversion of multiple if-else calls to poly2trellis by coder.
It seems to execute all function calls irrespective of the value of k.
got it, thanks!!
It does not execute all of the function calls, it compiles all of the function calls down into the specific code needed for that one trellis variety.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Error Detection and Correction에 대해 자세히 알아보기

제품

질문:

2017년 12월 26일

댓글:

2017년 12월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by