Send Variable to Workspace In Middle of a Function
28 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 17 Mai 2017
Réponse apportée : MathWorks Support Team
le 2 Juin 2017
Is there a way to return a variable to the workspace in the middle of a function? I do not want to create two separate functions in order to do this.
Réponse acceptée
MathWorks Support Team
le 17 Mai 2017
You can use the 'assignin' function. It allows you to assign a variable to a workspace in the middle of a function. If you wish to save multiple variables, you can either make a call to 'assignin' multiple times or save the variables in a container like a cell array or structure. You can refer to the documentation here.
https://www.mathworks.com/help/matlab/ref/assignin.html
To test this, write a function, debug the function, execute the 'assignin' line, and quit debugging. You will see the variable saved in the specified workspace even though the function did not fully execute.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Variables dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!