MATLAB Answers

How do I save variables from a function to the base workspace?

778 views (last 30 days)
Pocho
Pocho on 21 Aug 2012
Answered: Stacey on 13 Jan 2020
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 Comment
Daniel Shub
Daniel Shub on 22 Aug 2012
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?

Sign in to comment.

Accepted Answer

Ryan G
Ryan G on 21 Aug 2012
  4 Comments
Walter Roberson
Walter Roberson on 19 Nov 2016
In your script,
v0 = inptuVT();
and your inputVT.m would be
function v0 = inputVT
v0 = input('velocity');

Sign in to comment.

More Answers (2)

Stacey
Stacey on 13 Jan 2020
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
Azzi Abdelmalek on 21 Aug 2012
Edited: Azzi Abdelmalek on 21 Aug 2012
declare them as global variables
global var1 var2 var3
do it in your function and in matlab command
  4 Comments
Milad Abdollahi
Milad Abdollahi on 28 Jul 2015
If you set variables as global you can not using them in simulikn

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!