Is there a way to save a variable created in a function to the workspace?
이전 댓글 표시
I have a variable being created in a function and want to save in the workspace so the command window can access.
채택된 답변
추가 답변 (2개)
Aldin
2012년 3월 19일
0 개 추천
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
Oleg Komarov
2012년 3월 19일
generally, to swap variable from any specific workspace to the base one you can use:
assignin('base','someName',yourvar)
Aldin
2012년 3월 19일
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
2012년 3월 20일
I think "persistent" will help.
Just use
persistent variable_name = value
댓글 수: 1
Walter Roberson
2012년 3월 20일
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.
카테고리
도움말 센터 및 File Exchange에서 Data Type Identification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!