フィルターのクリア

How to use arrayfun in Simulink?

2 ビュー (過去 30 日間)
Andrew Poissant
Andrew Poissant 2017 年 8 月 25 日
編集済み: Andrew Poissant 2017 年 8 月 29 日
I am trying to use arrayfun in Simulink but first got the error "Function 'arrayfun' is not supported for code generation. Consider adding coder.extrinsic('arrayfun') at the top of the function to bypass code generation." Then I tried adding coder.extrinsic('arrayfun') before the arrayfun call but then I get an error saying "Cannot pass an object of class 'function_handle' to MATLAB function 'arrayfun'". Does anyone have a way to use arrayfun in Simulink? My code works in matlab but Simulink can't handle function handles. The code below is a simplified version of what I have in my model but serves the same purpose.
coder.extrinsic('arrayfun');
dx = [0 5 10 15];
n = 5;
dn_x = arrayfun(@(dx)linspace(0,dx,n), dx(2:end)', 'Uni',0);

採用された回答

Sudarshan Kolar
Sudarshan Kolar 2017 年 8 月 28 日
Hi Andrew,
The limitations of using function handles for code generation are mentioned here.
You are not allowed to pass function handles to extrinsic functions.
I am curious to learn more about why do you want to use 'arrayfun' with simulink. I am attaching a demo model for your reference. I am using Matlab Interpreted Function block to call 'arrayfun' inside Simulink.
Hope this helps you get started.
Sudarshan
  2 件のコメント
Andrew Poissant
Andrew Poissant 2017 年 8 月 28 日
編集済み: Andrew Poissant 2017 年 8 月 28 日
I have a start point, 0, and an endpoint, dx, and I need to fill in n points in between the two. Are there other ways to do this other than arrayfun in Simulink such that I do not need the Matlab Interpreted Function? I have a lot of other code before and after arrayfun is used so it would be easier to use and understand if it was all in my matlab function block.
Andrew Poissant
Andrew Poissant 2017 年 8 月 29 日
編集済み: Andrew Poissant 2017 年 8 月 29 日
I believe I may be able to just use linspace without arrayfun, only problem is my dx value are not scalars so it gives me an error when I just use linspace

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by