Using matlab function in simulink error -
i'm new simulink need use matlab function.
i created "matlab function1" block 1 input (a time signal comes block) , 1 output (three signals wrapped in matrix shown in scope block).
here code inside matlab function block:
function outputsignal = myfunction(input_signal) coder.extrinsic('lsim'); time = [1:1:length(input_signal)]; k_dia = [19.5 13 9.9]; k_dia = k_dia*10^-3; outputsignal = zeros(length(time), length(k_dia)); j = 1:length(k_dia) = [-k_dia(j) 0; k_dia(j) -k_dia(j)]; b = [1 0]'; c = [1 1]; d = 0; sistem = feval('ss', a, b, c, d); outputsignal(:,j) = lsim(sistem, input_signal, time); end end
previously had problems using functions "ss" , "lsim" because of code generation problems, should have solved them using feval , coder.extrinsic. have following error:
when simulating response specific input signal, input data u must matrix of numeric values @ least 2 rows (samples) , without nan or inf.
and can't understand if problem still these functions or if made mistake in how use matlab functions in simulink.
edit: understood problem because lsim needs input_signal of @ least length 2, while system giving input function of 1 single value @ every time step. if time of 10 steps , serie of values generated previous block [1 2 3 4 5 6 7 8 9 10], have input function:
- [1] @ step 1,
- [1 2] @ step 2,
- [1 2 3] @ step 3, ....
- [1 2 3 4 5 6 7 8 9 10] @ step 10.
of course since lsim doesn't work 1 value, @ step 1 use default output value.
i think need block memorizes happens in time steps before, scope block output.
since systems time invariant can create 3 separate state space systems each different parameter valued matrices , supply vector of 3 components input signals have left empty because don't know send from.
Comments
Post a Comment