Can you create an object in Simulink that can be referenced by multiple MATLAB Fcn blocks?

23 次查看(过去 30 天)
I've attached an image with my current Simulink set-up. I am needing to replace the Interpreted MATLAB Fcn blocks with MATLAB Fcn blocks in order to make my Simulink code generation compatible. However, I am struggling to find a way to mimick this similar OOP approach - where I am essentially creating a global object that is being referenced and manipulated by multiple blocks.
With the MATLAB Fcn block, it is only creating a local object for that specific block. It cannot be referenced and manipulated by another MATLAB Fcn block. I run into a similar issue when trying it with MATLAB System blocks. Is there a workaround for this to get this "global object" character?
  5 个评论
Roop
Roop 2024-8-7,17:28
编辑:Roop 2024-8-7,17:29
I don't belive this method works for objects of user-defined classes. For instance, my object has properties that return variable size structs, App Designer UI's, and other complicated data types. Are there any addtional potential workarouds?
Umar
Umar 2024-8-8,3:11
Hi @Roop,
To address your query regarding, “ I don't belive this method works for objects of user-defined classes. For instance, my object has properties that return variable size structs, App Designer UI's, and other complicated data types. Are there any addtional potential workarouds?”
I do understand that the set_param and evalin approach may not directly work for objects of user-defined classes with complex data types unless you utilize global variables within MATLAB because by declaring a variable as global within a function block, you can maintain its value across multiple function calls. Hope this helps.

请先登录,再进行评论。

回答(1 个)

Paul
Paul 2024-7-11
Hi Roop,
If you want to use global data inside Matlab Function blocks, start from Use Global Data in MATLAB Function Blocks to assess if any of the provided methods are sufficient for your use-case.
I do not know if the Matlab Function blocks support use of user-defined classes (UDC) as seems to be the case here. Even if so, I'm not sure if a UDC instance can be used as a global object, and, frankly, I suspect that won't pe possible because this Simulink paradigm is based on Simulink.Signal objects. If it isn't there may be other workarounds.
  4 个评论
Roop
Roop 2024-8-8,16:14
Hmm... yeah I think I might need to extract the particular data from my object that I am working with in Simulation. Unfortunately, my UDC is difficult to describe because proprietary work, but essentially I am intending to
  • Grab the object's current paramter data
  • Feed it into a S-Function (with MEX file) which is tied to an external model
  • Set the object's parameter data to the results
  • And continually iterate this process during the entire simulation time
Issue is maintaing the same instance of the object to read and write data to, which I was able to do with Interpreted Fcn blocks, but now that I need code generation compatibility, it is proving difficult to replace with MATLAB Fcn or MATLAB System blocks and get that same "global object" behavior.
Paul
Paul 2024-8-8,19:59
Is there really a need to update the object during simulation?
Or do you just need to iterate on the data during simulation?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by