How to load a cell array into a Simulink model?

19 visualizzazioni (ultimi 30 giorni)
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 Commenti
Terry Poole
Terry Poole il 17 Nov 2020
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 il 24 Dic 2022
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?

Accedi per commentare.

Risposte (1)

Fangjun Jiang
Fangjun Jiang il 17 Nov 2020
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.

Categorie

Scopri di più su Programmatic Model Editing in Help Center e File Exchange

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by