Complex matlab script migration into simulink

6 visualizaciones (últimos 30 días)
Kenneth
Kenneth el 25 de Jul. de 2024
Comentada: Paul el 31 de Jul. de 2024
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 comentarios
Kenneth
Kenneth el 29 de Jul. de 2024
Hi Paul,
The script that I am trying to migrate right now is modeling a communications system, when run in MATLAB it plots out 4 figures such as standard plots, etcetc. For ease of use for other people, I am trying to migrate this system onto simulink, to adopt a 'drag n drop' logic for users so they won't have to alter the lengthy script itself when changing parameters. What I have tried so far is dividing the entire script into initialization vs logic/calculations, having Simulink run the initializations(located as a .m file in matlab) as a preloadfcn which pumps those values into the primary simulink block that houses all of the calculation scripts. I have run into some code generation errors(you can see another similar question on my profile).
The workflow I was asking about here would be if there is some way to avoid running all of these scripts within simulink(what I described above) as adapting to code generation standards could make things messy, so if there exists a block within Simulink that when run, executes a .m file from the workspace, allowing the user to see plots generated by the script?
And to asnwer your questions -
correct, by clicking on a block I meant double clicking on it to run the scripts inside.
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.
For results, as mentioned above, would be plots as shown below - this was generated by layering several hundreds of lines onto a single plot using a for loop, so simply loading the plot data as a preLoadFcn would be very complicated.
I hope this cleared up some of your confusions, thank you so much for your time and effort!
Paul
Paul el 31 de Jul. de 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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Simulink Coder en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by