How do I save variables from a function to the base workspace?
显示 更早的评论
I have a matrix variable, corr_matrix. I would like to save this to the workspace without having to validate (export2wsdlg requests permission before exporting). Can you do this with evalin? I did not understand evalin's documentation...but I would like something like
Save2ws('variable_name', variable);
How can this be done?
1 个评论
Daniel Shub
2012-8-22
What you are asking for with Save2ws is a way to poof a variable. In general this is bad practice. Can you give some details about how/where corr_matrix is being created?
采纳的回答
更多回答(2 个)
Stacey
2020-1-13
3 个投票
If you would like to do this for debugging purposes, you can click on the down-arrow below "Run" and choose "Pause on Errors". This will allow you to browse the internal variables and workspace in a function in debug-mode when an error occurs.
Azzi Abdelmalek
2012-8-21
编辑:Azzi Abdelmalek
2012-8-21
declare them as global variables
global var1 var2 var3
do it in your function and in matlab command
4 个评论
Pocho
2012-8-21
Matt Fig
2012-8-21
Yes, avoid global variables if you possibly can, which is almost always. Experience debugging code that relied on global variables has taught me this lesson.
Daniel Shub
2012-8-22
@Matt while I try and avoid globals, I would never trade a global for a evalin/assignin. At least globals give you a fighting chance of figuring out what is happening.
Milad Abdollahi
2015-7-28
If you set variables as global you can not using them in simulikn
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!