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

조회 수: 409 (최근 30일)
Pocho
Pocho 2012년 8월 21일
답변: Stacey 2020년 1월 13일
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일
  댓글 수: 4
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일
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일
declare them as global variables
global var1 var2 var3
do it in your function and in matlab command
  댓글 수: 4
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by