Round function with multiple inputs not working in MATLAB function block in Simulink

Hi all,
I want to round a number to 3 decimal places. In MATLAB I can easily do it in this way:
>> number=25.0001;
>> round(25.0001,3)
ans =
25
If I try to do this in Simulink in a MATLAB Function block in this way:
function D_avg1 = fcn(m)
%#codegen
D_avg1 = round(m,3);
It gives error:
Error calling 'round'. This call-site passes more inputs to this function than it can accept.
Function 'BSD_System /Averaging/MATLAB Function' (#278.45.55), line 4, column 10:
"round(m,3)"
Launch diagnostic report.
Component: MATLAB Function | Category: Coder error
How to solve this?

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 7 月 7 日
Instead of round(u,3) use
round(u*1000)/1000

4 件のコメント

Ahmed Hafsi
Ahmed Hafsi 2018 年 1 月 3 日
It helped !! Very efficient ! Thanks !
Erwin Mooij
Erwin Mooij 2020 年 5 月 1 日
Any insight as to why it does not work? round(u,3) is a perfectly fine Matlab syntax. Is it because at the moment of initialising the model, Simulink does not now anything about the input "u" yet? I noticed in other situations as well that all data inside the embedded Matlab function should be known at the moment of initialisation.
Paul
Paul 2020 年 5 月 1 日
Only the single argument syntax is supported:
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
  • Code generation supports only the syntax Y = round(X).
  • Code generation does not support char or logical data types for X.
Paul
Paul 2020 年 5 月 2 日
I should have mentioned that if you want the 2-argument version declaring round as an extrinsic function should work.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by