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
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?

サインインしてコメントする。

 採用された回答

Ryan G
Ryan G 2012 年 8 月 21 日

3 投票

4 件のコメント

Pocho
Pocho 2012 年 8 月 21 日
This is what I was looking for, thank you.
Daniel Shub
Daniel Shub 2012 年 8 月 22 日
@Pocho if you look around you will see that using eval, evalin, and assignin are considered equally, if not more, evil than globals.
James Cannon
James Cannon 2016 年 11 月 19 日
編集済み: Walter Roberson 2016 年 11 月 19 日
in my script file: inputVT()
in my function file named inputVT.m
I have
v0 = input('velocity');
this works but my input is not stored to the workspace. How do I store it to ws?
Walter Roberson
Walter Roberson 2016 年 11 月 19 日
編集済み: Walter Roberson 2016 年 11 月 19 日
In your script,
v0 = inptuVT();
and your inputVT.m would be
function v0 = inputVT
v0 = input('velocity');

サインインしてコメントする。

その他の回答 (2 件)

Stacey
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
Azzi Abdelmalek 2012 年 8 月 21 日
編集済み: Azzi Abdelmalek 2012 年 8 月 21 日

0 投票

declare them as global variables
global var1 var2 var3
do it in your function and in matlab command

4 件のコメント

Pocho
Pocho 2012 年 8 月 21 日
I agree, global variables are generally not good practice, but this would work.
Matt Fig
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
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
Milad Abdollahi 2015 年 7 月 28 日
If you set variables as global you can not using them in simulikn

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeVariables についてさらに検索

質問済み:

2012 年 8 月 21 日

回答済み:

2020 年 1 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by