calling fi(var1, var2,..varN) in matlab function in a simulink model asks for constant values for input 2 to N
조회 수: 4 (최근 30일)
이전 댓글 표시
Hello,
I want to cast a value into fixed point in a matlab function in a simulink model. To do so I have a SLDD used by the model in which some parameters are defined for word length with the sotrage calss as const (I had the same issue with auto)
I made a function with several inputs (this is an example that gets the same error as my function) :
function [out1] = horCounter(in1, in2, W_HDISP)
out1 = in1 + fi(in2,0,W_HDISP,0);
end
I defined W_HDISP as a parameter in the symbol pane:
Whenever I try to simulate I get the following error message:
Inputs var2..varN in call to fi(var1, var2,..varN) must be constant. Input 3 is not a constant.
Function 'GENERIC/PATH/TO/FUNCTION/MATLAB Function' (#111.111.111), line 2, column 17:
"fi(in2,0, W_HDISP,0)"
Launch diagnostic report.
Is there a way to solve it in the function or do I have to put conversion blocs on my in2 before sending it in the function and get rid of the fi() function use?
댓글 수: 1
Guy Regev
2024년 2월 6일
The solution below will not work for HDL code generation. The general solution is to force simulink to regard Input3 i.e. your parameter as constant, and that can be achieved by going to the model tab, click on model explorer. Find this matlab function, click on it and click on the parameter in the parameter list that opened, another window will open on the right hand side (usually) and you'll see the "Tunable" property ticked. tick it off, save and you're done.
답변 (1개)
Andy Bartlett
2023년 6월 16일
I don't know if there is or is not a way to make the MATLAB Function block recognize that W_HDISP as a constant at update diagram time.
But there is a very powerful approach to achieve your goal. The approach is to follow the Cast Like pattern.
prototypeVarHDISP = fi([],0,16,0); % put in SLDD or where desired
function out1 = horCounter(in1, in2, prototypeVarHDISP)
out1 = in1 + cast( in2, 'like', prototypeVarHDISP);
end
In the Cast Like pattern, you create a "dummy" numeric variable whose purpose is just to communicate data type information. The value held by this variable doesn't matter; that's why I'm calling it a "dummy" variable. Only the numerictype of the "dummy" variable matters. This "dummy" variable is more elegantly called a Prototype.
The Prototype can be an individual argument to the function as in the example code above. Or, if you need multiple prototypes, then you can organize them into a structure as shown in this example in the documentation Write MATLAB Code That Is Independent of Data Types.
참고 항목
카테고리
Help Center 및 File Exchange에서 Fixed Point에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!