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

 Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 9 de Oct. de 2012
Editada: Andrei Bobrov el 9 de Oct. de 2012
R=roots([A B C D E]);
S=zeros(1,4);
t = abs(imag(R)) < eps(100);
S(t)=real(R(t));

Más respuestas (0)

Categorías

Más información sobre Simulink Coder en Centro de ayuda y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by