Size mismatch error using Matlab function to solve equations

Hi All,
Im trying to use matlab function in simulink using the following code:
  1. function S= fcn (A,B,C,D,E)
  2. R=roots([A B C D E]); %ABCDE are coefficients of a polynomial that i want to solve and are preovided as real constants
  3. k=(zeros(1,4));
  4. k=R(imag®==0);% to discard the complex roots. this is my requirement
  5. k=real(k);
  6. S=zeros(1,4);
  7. S(:)=k;
The size of S is specified as [1,4] in the model explorer. I have to use fixed size calculations. When I run this code, I get a runtime error, "simulation stopped due to size mismatch error 4~=0." When I stop the debugger, the function block gets highlighted and I get the following error,: MATLAB Function Interface Error: Unknown MATLAB error encountered. Block Equation (#1512) While executing: none
Can somebody help me plese? Thanks in advance

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 10월 9일
편집: Andrei Bobrov 2012년 10월 9일
R=roots([A B C D E]);
S=zeros(1,4);
t = abs(imag(R)) < eps(100);
S(t)=real(R(t));

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Simulink Coder에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by