Change variables in the base workspace through a Matlab Function block
Mostrar comentarios más antiguos
Hi,
I'm trying to change a matrix (of type double) in the base workspace through a Matlab Function block in Simulink. To access the matrix in the base workspace within the Matlab function block, I have set the variable type in the Symbols pane of the Matlab function block to parameter data. Then I change the parameter and assign it to the base workspace with the assignin function, which I found in past solutions for the same problem.
Here is an example of my problem:
function updateBaseWorkspaceVariable(Workplan, TasksToDo)
% Modify the base workspace variable using the parameters
assignin('base', 'myVariable', Workplan + TasksToDo);
end
However when running my code and this example code I get the following error message:
Error:Function 'assignin' not supported for code generation.
Function 'MATLAB Function' (#343.124.176), line 3, column 5:
"assignin('base', 'myVariable', Workplan + TasksToDo)"
Launch diagnostic report.
Since this is a solution already used in past Matlab versions I'm wondering, if it's a problem within the Matlab version that I'm using (23a) or whether there is something I'm missing.
Thanks in advance for your help!
Kind regards
Lisa
Respuesta aceptada
Más respuestas (1)
Harald
el 21 de Sept. de 2023
0 votos
Hi Lisa,
I would question the workflow of writing to the base workspace every time the block is executed. If you only need to have the variable in the workspace after the simulation, you can use model callbacks.
Best wishes,
Harald
1 comentario
Lisa P
el 22 de Sept. de 2023
Categorías
Más información sobre Event Functions en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!