I have a very simple question: how to update GUI data using programmed GUI (without GUIDE). The following is my code:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Matlab GUI without Guide
% 05/15/2012
function simpleGuiclear all;close all;clc;h.counter = 0;h.fig = figure('position',[1000,500,210,60]);h.button = uicontrol('style','pushbutton',... 'position',[10,10,100,40],... 'string','button');set(h.button,'callback',{@increment,h});function increment(hObject,eventdata,h)h.counter = h.counter + 1;set(h.button,'string',num2str(h.counter));%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Basically I want to display the value of h.counter on the button. I thought I was incrementing h.counter every time h.button is pressed so I expected 1,2,3,4… showing on the button as I clicked, but h.counter was always 1. Why was h.counter not updated?
Any suggestions?
Yunde
Best Answer