Complex matlab script migration into simulink
Show older comments
I'm currently working with a rather length Matlab script, and am trying to move it onto simulink to adopt a more 'drag n drop' logic flow, as in Simulink we are able to use both custom function blocks as well as default lib blocks. After trying to move this script to Simulink I realized that I have been running into a lot of code generation incompatibility errors, I'd like to ask whether I can "pull" a plot from the base Matlab workspace into Simulink when I run a Simulink function?
Say that I click on a specific block on Simulink that triggers a script in the base workspace to run, and then the results and plots from the base workspace script are "sent" to Simulink.
Is this achievable?
Thanks!
4 Comments
Walter Roberson
on 25 Jul 2024
Well, you could potentially save() data and plotting at the MATLAB level, and then in a MATLAB Function Block, load() it...
However, incorporating such graphics into a Simulink scope might be... difficult.
Paul
on 28 Jul 2024
Hi Kenneth,
Can you provide a lot more clarification on the desired workflow?
Considering the specific question:
"Say that I click on a specific block on Simulink that triggers a script in the base workspace to run, and then the results and plots from the base workspace script are "sent" to Simulink."
"Say that I click on a specific block"
Do you mean double-click?
What kind of block are we talking about? A library block, a subsystem, something else?
By "triggers a script" do you mean a script that executes from a block callback function, like the OpenFcn?
"results and plots from the base workspace script are "sent" to Simulink"
What kind of results are we talking about and how would those results be used in the Simulink model?
What does sending a plot to Simulink mean?
Kenneth
on 29 Jul 2024
Paul
on 31 Jul 2024
As for what type of block, I am referring to a custom MATLAB function block within simulink, one where you can script your own functions inside.
correct, by clicking on a block I meant double clicking on it to run the scripts inside.
The Matlab Function in Simulink is intended for running Matlab code when as part of a Simulink simulation. Double clicking on that block in the diagram is typically meant to open the editor to edit its code, add parameters, etc. Double clicking on that block is not typically meant to run its code (though it may be possible to do so with some effort depending on the actual behavior that's desired). Perhaps I still don't understand what you're trying to accomplish, but at this point I'm not even sure that Simulink, which is intended for forward-time simulation, is the right tool to use.
Answers (0)
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!