How to save a variable from a function and use it in another function in MATLAB GUI?
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi,
I have made a MATLAB GUI which has two buttons. I want to perform some tasks on CallBack event of both these buttons.
I have obtained a variable FileName when the first button is pressed. But as soon as the function of first button ends, the variable gets deleted. I want to use this variable when the second button is pressed which is obviously a different function. Since, the first function variable is deleted as soon as the function ends, how can I use this variable within the second button's function.
I know how to do it by saving it as .mat and recalling it but it will make the GUI interface unfriendly. Can you please tell me another way to save a variable before the first function ends and recall it later in the second function?
Thank you.
댓글 수: 0
채택된 답변
Gerd
2011년 6월 22일
Hi Asad,
before the "first button" function end use
mydata.value = "directory result"
setappdata(gcf,'mydata',mydata);
At the beginning of the "second button" function use
mydata = getappdata(gcf, 'mydata');
disp(mydata.value); % shows the value
추가 답변 (1개)
Sean de Wolski
2011년 6월 22일
댓글 수: 1
Krishna Kumar
2011년 6월 22일
Yes.I had suggested the same
in OP's thread in newsgroup-http://www.mathworks.com/matlabcentral/newsreader/view_thread/309582
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!