Need help with set_param
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello,
I am currently trying to use set_param to set the parameters of my transfer function block in simulink. This is working fine for the numerator but not the denominator. I think this is due to the fact that the denominator is a 1x2 instead of a single number like the numerator. Here is my simple code below.
[num,denon] = filtcoef(cutoff(x),order); set_param('instsys/Generic Filter','Numerator',num2str(num)); set_param('instsys/Generic Filter','Denominator', num2str(denon));
SimOut = sim('instsys');
this works with my other scripts but in those cases both the inputs where single numbers not vectors/matrixes. the error I am getting is
Error using effectoffilter (line 15) Invalid setting in 'instsys/Generic Filter' for parameter 'Denominator'.
Caused by: Error using effectoffilter (line 15) Expression '1 62.8319' for parameter 'Denominator' in 'instsys/Generic Filter' cannot be evaluated. Error using effectoffilter (line 15) Error: Unexpected MATLAB expression.
Thank you for the help
댓글 수: 0
답변 (1개)
MULI
2024년 3월 28일
편집: MULI
2024년 3월 28일
Hi Noah,
When you are trying to set the denominator parameter it failed because the format of the string passed to “set_param” is not properly represented.
The function “num2str” converts denominator vector into a string generates a space-separated list of numbers which is not a valid MATLAB expression for a vector. Simulink expects the vector to be formatted in MATLAB syntax, enclosed in square brackets with elements separated by spaces or commas
To rectify this use “mat2str” for converting the denominator to a string. This converts a vector into a valid MATLAB expression format including the necessary square brackets.
Here I am providing the example code snippet
% Convert the numerator and denominator to a string representation of a MATLAB vector
numStr = mat2str(num); % Converts to a string with square brackets, e.g., "[1, 5]"
denonStr = mat2str(denon); % Converts to a string with square brackets, e.g., "[1, 2, 3]"
% Set the parameters for the Transfer Function block
set_param('instsys/Generic Filter', 'Numerator', numStr);
set_param('instsys/Generic Filter', 'Denominator', denonStr);
You may refer to this documentation link for more information on “mat2str”
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!