Você está na página 1de 11

ANALOG CLOCK

USING MATLAB
PROBLEM STATEMENT:
Making a clock in GUI MATLAB

Graphical User Interface.


Creating a MATLAB GUI
Programmatically:

MATLAB® apps are self-contained MATLAB


programs with GUI front ends that automate a
task or calculation. The GUI typically contains
controls such as menus, toolbars, buttons, and
sliders.
For more control over design and development,
you can also create MATLAB code that defines all
component properties and behaviors.
MATLAB contains built-in functionality to help you
create the GUI for your app programmatically.
You can add dialog boxes, user interface controls
(such as push buttons and sliders), and
containers (such as panels and button groups).
• GUI-Graphical User Interface.

• The graphical user interface (GUI )is a type of user


interface that allows users to interface with electronic
devices, through graphical icons and visual indicators
such as secondary notation, instead of text-based
user interfaces, typed command labels or text
navigation
Click icon to add picture ANALOG
DISPLAY
CLOCK
• On using GUI MATLAB
and writing a code that
includes the axis of
clock, the seconds hand,
the minutes hand and
the hours hand
• Also the date is
displayed along with the
clock.
• The time and date of
your code is directly
accessed from your
system i.e., the clock we
designed shows us the
time that our system or
PC is set to.
MATLAB CODE:
 function clock

 % CLOCK Analog display clock.

 clf

 shg

 axis([-1.1 1.1 -1.1 1.1])

 axis square

 axis off

 x = sin(2*pi*(1:60)/60);

 y = cos(2*pi*(1:60)/60);

 k = 5:5:60;

 line(x,y,'linestyle','none','marker',‘^’,'color','black','markersize',2)

 line(x(k),y(k),'linestyle','none','marker','*','color','black','markersize',8)

 h = line([0 0],[0 0],'color','blue','linewidth',4);

 m = line([0 0],[0,0],'color','blue','linewidth',4);

 s = line([0 0],[0 0],'color',[0 2/3 0],'linewidth',2);

 gray = [.93 .93 .93];


 klose = uicontrol('string','close','style','toggle');

 while get(klose,'value')==0

 c = clock;

 af = (c(2)==4 && c(3)==1);

 text(-0.4,-1.2,datestr(datenum(c(1),c(2),c(3))),'fontsize',16)

 t = c(4)/12 + c(5)/720 + c(6)/43200;

 if af, t = -t; end

 set(h,'xdata',[0 0.8*sin(2*pi*t)],'ydata',[0 0.8*cos(2*pi*t)])

 t = c(5)/60 + c(6)/3600;

 if af, t = -t; end

 set(m,'xdata',[0 sin(2*pi*t)],'ydata',[0 cos(2*pi*t)])

 k = ceil(c(6));

 if af, k = 61-k; end

 set(s,'xdata',[0 x(k)],'ydata',[0 y(k)])

 pause(1.0)

 end

 close(gcf)
DESCRIPTION OF CODE:
 clf -Clears the current figure.

 shg-Shows the graph window. shg brings the current figure window forward .

 axis- sets the scaling for the x-, y- and z-axes on the current 3-D plot .

 line -adds the line in vectors X and Y to the current axes.


 uicontrol -creates a user interface control in the specified figure.
uicontrol('PropertyName1',value1,'PropertyName2',value2,...)
 get-V = get(H,'PropertyName') returns the value of the specified property for the
graphics object with handle H.
 text-text(X,Y,'string') adds the text in the quotes to location (X,Y)on the current axes

 datestr- String representation of date.

 Datenum-N = datenum(V) converts one or more date vectors V into serial date
numbers N.
 set-set(H,'PropertyName',PropertyValue) sets the value of the
specified property for the graphics object with handle H.
 ceil-ceil(X) rounds the elements of X to the nearest integers
towards infinity.
 Pause- pause(n) pauses for n seconds before continuing, where n
can also be afraction.
 gcf -Get handle to current figure. H = gcf returns the handle of
the current figure. The current figure is the window into which
graphics commands like PLOT,TITLE, SURF, etc. will draw.

So using this code we’ve first created the axis and then plotted the
circle.
Later we’ve given the linestyle of the analog clock. Then we
written a code for hours hand , minutes hand and seconds hand to
display on the clock. We then had given the code to set date and
time from the system that is set on our system.
OUTPUT:
In this way
we can run
the code &
our Analog
Clock gets
displayed…
YOU
ANK
TH

Você também pode gostar