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 日

1 投票

R=roots([A B C D E]);
S=zeros(1,4);
t = abs(imag(R)) < eps(100);
S(t)=real(R(t));

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSimulink Coder についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by