How to use handles in a function??

조회 수: 2 (최근 30일)
Jethro
Jethro 2012년 1월 19일
Hi everybody!
I need to use a pushbutton handles in a function that I use in my fig's .m file.
I have to use a set: at the end of the actions made by the function, this pushbutton has to be shown...
When I run my function, naturally it tells to me that it can't recognize the handles (because in the function there're no handles!)... There's a way to "globalize" my handles??
I don't know if it's correct to assign a variable to my handles, something like
var=handles.tag;
or to use "setappdata" and "getappdata" functions... Can anyone help me?? Thanks a lot!!

채택된 답변

Walter Roberson
Walter Roberson 2012년 1월 19일
Before the line that accesses handles, add
handles = guidata(gcf);

추가 답변 (2개)

Jan
Jan 2012년 1월 19일
Currently the description of the problem is not clear. The values or the handles cannot be "published" automatically. Storing them using SETAPPDATA is not helpful also, because usually the handles struct is stored in the ApplicationData by calling guidata already.
Please explain the problem again with more details by editing the original message - not as comment or answer.

Jethro
Jethro 2012년 1월 19일
So... I create (helped by users' answers) a function, separated from my .m file, that creates me a number of pushbutton based on unique of arrays.
In this function I set everything (like tag, callback, String...) and naturally, in callbacks, actions that my pushbutton has to do. Now, when I press one of pushbuttons generated by my function, I have to start a set: this set must make visible another pushbutton, that already exists in my guide (it's set as 'visible', 'off').
The code I have to insert in my function file is like
set(handles.PB_back, 'visible', 'on');
If I add it like that, Matlab shows me an error:
??? Undefined variable "handles" or class "handles.PB_Rit_Ist".
Error in ==> GUI1 at 72
set(handles.PB_Rit_Ist, 'visible', 'on');
??? Error while evaluating uicontrol Callback
because in the function file there's no handles!
So I have to "generalize" this handles in my fig's .m file to use it in this function... How can I do it??
  댓글 수: 1
Jethro
Jethro 2012년 1월 19일
If you write it in a new answ, I can choose yours, 'cause you solved my prob!

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

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by