Is there a way to save a variable created in a function to the workspace?
Mostrar comentarios más antiguos
I have a variable being created in a function and want to save in the workspace so the command window can access.
Respuesta aceptada
Más respuestas (2)
Aldin
el 19 de Mzo. de 2012
0 votos
If you working in GUI i THINK that's impossible. It is an mistake in MATLAB because the data are not permanent as in Java.
2 comentarios
Oleg Komarov
el 19 de Mzo. de 2012
generally, to swap variable from any specific workspace to the base one you can use:
assignin('base','someName',yourvar)
Aldin
el 19 de Mzo. de 2012
Hi Oleg. Sorry for my behavior. Thank you. I didn't know that.I think It would be better for MATLAB to think object oriented.
Sahyadri Vibhu
el 20 de Mzo. de 2012
I think "persistent" will help.
Just use
persistent variable_name = value
1 comentario
Walter Roberson
el 20 de Mzo. de 2012
That is not valid syntax. You can use
persistent variable_name
to indicate that the variable keeps its value between calls. You cannot, though, initialize it in the same statement, and doing so would be a waste of the idea that you want to pull back the value the variable had in the last function call.
Categorías
Más información sobre Programming 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!