Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
gui question

Subject: gui question

From: Vihang Patil

Date: 11 Apr, 2008 14:09:01

Message: 1 of 4

Hello

I have a gui lets says gui.fig with one pushbutton with
tag "pushbutton1" and one edit box with tag "edit1"

Now, I want to update a count as I press the pushbutton
and see the updated count in my edit box.

My question is that, I want to call a function from
pushbutton say "update_counter" and that function should
have a counter that keeps on updating when I press the
pushbutton.
I can update the counter from pushbutton callback also and
see the updated count in the edit box , but I dont want it
that way. I want a function to be called "update_counter"
from the pushbutton's callback that will update the
counter, send the updated count back to pushbutton and
then the pushbutton will display in the edit box

This is what I have tried, but it does not update in the
edit box

% --- Executes just before gui is made visible.
function gui_OpeningFcn(hObject, eventdata, handles,
varargin)

handles.guifig = gcf;
handles.counter = 0;

set(handles.edit1,'String',num2str(handles.counter));

% Choose default command line output for untitled
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
update_counter(handles);
set(handles.edit1,'String',num2str(handles.counter));
guidata(hObject, handles);


%----Update Function
function handles = update_counter(handles)

handles = guidata(handles.guifig);
handles.counter = handles.counter + 1;
guidata(handles.guifig, handles);


Please guide. I see only "0", even though I repetedly
press the Pushbutton

Vihang

Subject: gui question

From: Alessandro C.

Date: 16 Apr, 2008 07:23:02

Message: 2 of 4

Hi Vihang,

You could try to define the output of function
update_counter as a global variable.

HTH

Alessandro

Subject: gui question

From: French Caro

Date: 16 Apr, 2008 07:51:02

Message: 3 of 4

Hi,
You may try (the change is on line 3) :

% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
handles=update_counter(handles);
set(handles.edit1,'String',num2str(handles.counter));
guidata(hObject, handles);

Because between update_counter and the set, you don't have
the update of handles.
HTH

Subject: gui question

From: Vihang Patil

Date: 17 Apr, 2008 12:40:21

Message: 4 of 4

"French Caro " <caro95470@nospam.free.fr> wrote in message
<fu4b55$sb8$1@fred.mathworks.com>...
> Hi,
> You may try (the change is on line 3) :
>
> % --- Executes on button press in pushbutton1.
> function pushbutton1_Callback(hObject, eventdata,
handles)
> handles=update_counter(handles);
> set(handles.edit1,'String',num2str(handles.counter));
> guidata(hObject, handles);
>
> Because between update_counter and the set, you don't
have
> the update of handles.
> HTH

Thanks French Caro
That information was helpful
Regards
Vihang

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us