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

조회 수: 2 (최근 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일
편집: Roop 2024년 8월 7일
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일
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일
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일
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