To talk on Icrontic, just register!

It only takes 30 seconds.

Have an account? Sign in:

Forgot?
tmh88
Custom User Title
tmh88
2,487 Posts

gui matlab help

Hey, I'm messing around gui for a digital clock that I'm making in matlab and I'm stuck. I have drop down file with 'Exit' in it. I'm obviously trying to make it so when you select exit, the figure closes, but I can't figure it out. Any suggestions to get the exit button working?

heres what I have so far. The first block of code is the working one just so you can see what it looks like. To exit you have to use ctl+C. The second code block is what I think it should be, but doesn't work.

Code:
HFIG = figure('Name', 'Digital Clock', 'Numbertitle', 'off', 'Position', [400 300 350 100], ...
    'Menubar', 'none', 'Resize', 'on');
 filemenu = uimenu('Label', 'File');
uimenu(filemenu, 'Label', 'Exit', 'Callback', [mfilename, '(''EXIT'')']);

th = text(0.5,0.5,'xxx') ; % retrieve handle
set(gca,'visible','off') ;
set(th,'visible','on','horizontalalignment','center')
while(1),
  c1 = datestr(clock,13) ;
  set(th,'string',c1);% set the string
  pause(.1) ; % break with ctrl-C
  end

and heres the code for what I think it should be. Doesnt work though
Code:
if narg < 1
HFIG = figure('Name', 'Digital Clock', 'Numbertitle', 'off', 'Position', [400 300 350 100], ...
    'Menubar', 'none', 'Resize', 'on');
 filemenu = uimenu('Label', 'File');
uimenu(filemenu, 'Label', 'Exit', 'Callback', [mfilename, '(''EXIT'')']);

th = text(0.5,0.5,'xxx') ; % retrieve handle
set(gca,'visible','off') ;
set(th,'visible','on','horizontalalignment','center')
while(1),
  c1 = datestr(clock,13) ;
  set(th,'string',c1);% set the string
  pause(.1) ; % break with ctrl-C
  
else
  switch cmd
          case 'EXIT'
          close(HFIG);
  end
end
__________________





Armo, thanks for hosting
tmh88
Custom User Title
tmh88
2,487 Posts
bump, sorry. I'm still stuck and I hate to start on programs and then not be able to fnish them.
shwaip
elaborate bot
shwaip
5,729 Posts
Chat with me on AIM. I have questions...
__________________ my photostream for ic photography challenge

Anyone who wants dropbox, please use my referral link
tmh88
Custom User Title
tmh88
2,487 Posts
thanks a lot for the help shwaip

heres the updated code that works now. Also made the font larger.

Code:
done = 0;
HFIG = figure('Name', 'Digital Clock', 'Numbertitle', 'off', 'Position', [400 300 350 100], ...
    'Menubar', 'none', 'Resize', 'on');
 filemenu = uimenu('Label', 'File');
uimenu(filemenu, 'Label', 'Exit', 'Callback', 'done=1;');

th = text(0.5,0.5,'xxx','FontSize', 35) ; % retrieve handle
set(gca,'visible','off') ;
set(th,'visible','on','horizontalalignment','center')
while(~done),
    c1 = datestr(clock,13) ;
    set(th,'string',c1);% set the string
    pause(.1) ; % break with ctrl-C
end
close(HFIG);
tmh88
Custom User Title
tmh88
2,487 Posts
Alright I have everything how I want it, except for one thing.... I added buttons that show the hour of the other time zones. When you press them, the number appears on the screen. Anyway I want to be able to have a reset button, which starts the program over and clears those numbers. Anyone have some advice for it. Heres the code that I have

Code:
% This program is of a clock that shows the current time in other zones of
% the US. The large main numbers is the current time in the Easter timezone. When you press
% the other buttons for the zones(pacific,western,central), it shows the
% hour of that time(not the minutes). This program also has a date feature. 

clear1 = 0;
done = 0;
about = 0;
thedate = 0;
pacific = 0;
mountain = 0;
central = 0;
HFIG = figure('Name', 'Digital Clock', 'Numbertitle', 'off', 'Position', [450 300 400 100], ...
    'Menubar', 'none', 'Resize', 'on');
 filemenu = uimenu('Label', 'File');
 aboutmenu = uimenu('Label', 'About');
uimenu(filemenu, 'Label', 'Exit', 'Callback', 'done = 1;');
uimenu(filemenu, 'Label', 'Clear', 'Callback', 'clear1 =1;');
uimenu(aboutmenu, 'Label', 'About', 'Callback', 'about = 1;');
uicontrol(HFIG, 'Style', 'PushButton', 'Position', [10 10 75 25], ...
   'String', 'Date', 'Callback', 'thedate = 1');
uicontrol(HFIG, 'Style', 'Pushbutton', 'Position', [85 10 75 25], ...
   'String', 'Done', 'Callback', 'done = 1;');
uicontrol(HFIG, 'Style', 'Pushbutton', 'Position', [160 10 75 25],...
   'string', 'Central Time','Callback', 'central = 1;');
uicontrol(HFIG, 'Style', 'Pushbutton', 'Position', [235 10 75 25],...
   'string', 'Mountain Time','Callback','mountain = 1;');
uicontrol(HFIG, 'Style', 'Pushbutton', 'Position', [310 10 75 25],...
    'string', 'pacific','Callback','pacific = 1;');
th = text(0.5,0.5,'xxx','FontSize', 35) ; % retrieve handle
set(gca,'visible','off') ;
set(th,'visible','on','horizontalalignment','center')

while(~done),
    c1 = datestr(clock,14) ;
    set(th,'string',c1);% set the string
    pause(.1) ; % break with ctrl-
    
    if(thedate),
        msgbox( DATE , 'Date');
        thedate=0;                

    else if(central),
        a = str2num(datestr(now,'HH'))
        b = a-2+1
        if b>12
            b = b-12
        end
        tg= text(.5,.9,'xxx','Fontsize',10')
        set(tg,'string',b);   
        central = 0;
        
    else if(mountain),
        c = str2num(datestr(now,'HH'))
        d = c-3+1
        if d>12
            d = d-12
        end
        tg= text(.7,.9,'xxx','Fontsize',10')
        set(tg,'string',d); 
        mountain = 0;
   
        else if(pacific),
        e = str2num(datestr(now,'HH'))
        f = e-4+1
        if f>12
            f = f-12
        end
        tg= text(.9,.9,'xxx','Fontsize',10')
        set(tg,'string',f);
        pacific = 0;
  
              
        else  if(about),
        load gong 
        wavplay(y)
        msgbox( 'This program displays the current time in the eastern zone. It also shows the hour of the the 3 other time zones when you press the according buttons. This was writting by Trevor Holloway and Charles Silcott for EE 103', 'About message box');
        about = 0;
        
        if (clear1);
            
            clear1 = 0;
    end
    end
    end
    end
    end
    end
end
close(HFIG);
Similar Threads
Thread Thread Starter Forum Replies Last Post
Solving multiple equations using Matlab avi2112ben Matlab Help 3 22 Feb 2008 8:58pm
MatLab problem - inline function zero finder PGolasze Matlab Help 4 10 May 2007 12:38am
Need matlab help urgently shermaine Matlab Help 3 10 Nov 2006 1:00am
MATLAB code help please.... jennifer22cute Matlab Help 0 18 Sep 2006 8:53pm
MATLAB help= jpeg to avi dalisay Web & Digital Media 0 13 May 2006 5:03pm

Go Back   Icrontic Forums > Tech: Software > General Software > Matlab Help
Jump to
This Thread Search this Thread
Search this Thread:

Advanced Search


Current time: 9:33am (GMT)
Powered by vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Get Vanilla instead. Trust me.