How to load a cell array into a Simulink model?

53 ビュー (過去 30 日間)
Jose Antonio Aliaga
Jose Antonio Aliaga 2019 年 6 月 12 日
コメント済み: Benoit Beaulieu 2022 年 12 月 24 日
Hello. I've got some cell arrays made out of function handles. I'd like to load them into a Simulink model as inputs of a MATLAB function block. My goal to avoid the intern use of evalin, speeding up the performance of the model.
The constant block simply doesn't accept the matrices and the FromWorkspace block neither, it throws an error after execution. Is there any way to do this without resorting to the evalin function?
Here is part of the Simulink model with FromWorkspace blocks, to help you visualize it.
CTCFunc.PNG
Thank for your time.
  • Jose
  3 件のコメント
Terry Poole
Terry Poole 2020 年 11 月 17 日
I had a similar problem when I used tfdata to get the coefficients from a transfer function. I needed to call the transfer function to simulink and had to have the numerator and denominator to do so. The problem with the tfdata function was that it returned the numerator and denominator as cell arrays and the simulink block would throw an error if I called the given cell array. I worked around this by referencing the specific cell for instance.
My transfer function was defined as Ks....... I extracted the numerator and denominator with
[Ks_num, Ks_denom] = tfdata(Ks);
in the simulink transfer function block if I entered Ks_num in the numerator bar it would throw an error.
But if I entered Ks_num{1} it worked fine.
So the answer to your question I believe is to reference the cell when calling the data.
Benoit Beaulieu
Benoit Beaulieu 2022 年 12 月 24 日
I have the same issue. I am using a customtable in a simulink mask. Its data type is Cell array and I need to throw the complete data into a matlab function block.
How can it be done?

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

回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2020 年 11 月 17 日
According to this: Data Types Supported by Simulink, neither "cell array" nor "function handle" is mentioned. I don't know how you make it work in Simulink. Reference cell using {} or function handle in MATLAB Function block doesn't really count as using them in Simulink. Keep in mind that MATLAB Function block is executed at every simulation step. There must be a different way to handle those data types outside of Simulink.

カテゴリ

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

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by