Error using c2d extraction for block initialization

조회 수: 3 (최근 30일)
Adam Keller
Adam Keller 2015년 6월 10일
답변: Drew Davis 2015년 6월 11일
if order == 2
sys1 = tf([1], [1/(omega^2) 1.4142/omega 1]);
d_sys = c2d(sys1,Ts);
x = d_sys.num{1} %%error is here
y = d_sys.den{1} %%error is here
set_param([gcb '/filter_1'], 'SampleTime', 'Ts');
set_param([gcb '/filter_1'],'Numerator', 'x', 'Denominator', 'y')
elseif order == 1
sys1 = tf([1], [1/omega 1]);
d_sys = c2d(sys1,Ts);
x = d_sys.num{1} %%error is here
y = d_sys.den{1} %%error is here
set_param([gcb '/filter_1'], 'SampleTime', 'Ts', 'Numerator','x','Denominator', 'y');
else
fprintf('Error');
end
In my code I am initializing a mask for a block I made. "filter_1" is a discrete time transfer function, and I am trying to set the numerator and denominator parameters. There error I am recieving is:
"Error in 'butter/Subsystem': Initialization commands cannot be evaluated. Caused by: Invalid setting in 'butter/Subsystem/filter_1' for parameter 'Numerator'."
I am just trying to extract the numerator and denominator coefficients from 'd_sys' and use those to intialize my block. Help! Thanks in advance.

채택된 답변

Drew Davis
Drew Davis 2015년 6월 11일
I am assuming the code you posted lives only in the mask initialization of your block. In that case the variable 'x' and 'y' go out of scope after the block initialization is performed. You can ensure that the variables 'x' and 'y' are put in the base workspace by using the evalin or assignin command inside the mask.
Alternatively, you can set the numerator/denominator to their respective numeric value by performing the following command:
set_param([gcb '/filter_1'],'Numerator', ['[' num2str(x) ']'], 'Denominator', ['[' num2str(y) ']'])

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by