I want to debug a Matlab function block in Simulink
53 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
i wrote a piece of code and put it in a matlab function block in my Simulink model.
Now i want to debug that code and check those variables and the value of them in the workspace, as i known from a normal matlab script.
Obviously not a single variable appears in the workspace.
Does anyone know an answer for that problem?
Many thanks and greets :)
0 comentarios
Respuestas (2)
Dinesh Yadav
el 30 de Oct. de 2019
Hi,
I am attaching the files where i have done debugging in a simple program in simulink using MATLAB functions. First step is go to Model Configuration Parameters->Data Import/Export. Check the parameters as you required. I have unchecked everything as I am using To/From Workspace block to directly read and write into the MATLAB workspace.
I have inputted an array from my workspace, you will need to create an input array for simulink block to take.
While debugging inside the MATLAB function you can see the flow of program by placing breakpoints but you can see the value of variables change/update only once the control comes out of the MATLAB function block by placing a To Workspace block and recoding the value of variables you desire.
If you want to see the values being updated in real time even before the control comes out of the MATLAB function block you can use disp(varx) command to display the values updated at each time step. The output of disp will not come in the command window or workspace variable rather the values will be printed inside the View Diagnostic window during the debugging process.
Hope it helps.
0 comentarios
Benoit Beaulieu
el 18 de Nov. de 2022
I know it might be a little late to reply but I had the same issue, and I think I might help others landing on the page. Knowing Matlab interpreted function are no longer a thing since 2022b, I had to change.
Therefore, I found the best workaround, which is .... Not to code in the Matlab function block.
Instead, make a standard matlab function file and call it from the Simulink block as if it was from an external library.
Moreover, some Matlab functions are not supported by Simulink. (Such as "syms") Tagging your function as "extrinsic" before calling it will allow you to work without such restrictions.
% With the MyCustomFunction.m file in the project's directory, Call this from the Matlab function block IDE
coder.extrinsic("MyCustomFunction");
output = MyCustomFunction(input, varargin);
Hope this helps :)
0 comentarios
Ver también
Categorías
Más información sobre Simulink Functions en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!