how to make values global in matlab gui?

조회 수: 1 (최근 30일)
Dimitri
Dimitri 2015년 3월 12일
댓글: Dimitri 2015년 3월 12일
Hello all,
I found some similar questions already but unfortunately none of the answers worked for me.
I'm writing a very simple image viewer in Matlab Gui.
I have this code in the beginning :
handles.folder = 'myfolder';
folder_content = dir(handles.folder);
folder_content(1:2) = [];
so, the image viewer takes photos from that folder
and I want this to be a global, so that I won't have to write the same code in every push button callback or slider call back.
I tried
guidata(hObject,handles);
and global function, but they didn't work.
thanks in advance,
Dimitri
  댓글 수: 1
Stephen23
Stephen23 2015년 3월 12일
Avoid globals, and use the method that Adam suggests.

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

채택된 답변

Adam
Adam 2015년 3월 12일
Your code will allow
handles.folder = 'myfolder';
to be accessible in any callback. The code you wrote after that is just in the scope that you wrote it so if you want that elsewhere also you need
handles.folder_content = folder_content;
guidata( hObject, handles )
or the equivalent also.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by