How to load a cell array into a Simulink model?
이전 댓글 표시
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.

Thank for your time.
- Jose
댓글 수: 3
Jose Antonio Aliaga
2019년 6월 14일
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
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
2020년 11월 17일
0 개 추천
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.
카테고리
도움말 센터 및 File Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!