我是靠谱客的博主 可靠板栗,最近开发中收集的这篇文章主要介绍matlab的gui倒计时,GUI设计时钟程序中的计时器建立,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

我目前的程序如下:

function varargout = naozhong(varargin)

% NAOZHONG M-file for naozhong.fig

%      NAOZHONG, by itself, creates a new NAOZHONG or raises the existing

%      singleton*.

%

%      H = NAOZHONG returns the handle to a new NAOZHONG or the handle to

%      the existing singleton*.

%

%      NAOZHONG('CALLBACK',hObject,eventData,handles,...) calls the local

%      function named CALLBACK in NAOZHONG.M with the given input arguments.

%

%      NAOZHONG('Property','Value',...) creates a new NAOZHONG or raises the

%      existing singleton*.  Starting from the left, property value pairs are

%      applied to the GUI before naozhong_OpeningFcn gets called.  An

%      unrecognized property name or invalid value makes property application

%      stop.  All inputs are passed to naozhong_OpeningFcn via varargin.

%

%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one

%      instance to run (singleton)".

%

% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help naozhong

% Last Modified by GUIDE v2.5 30-Aug-2009 20:19:19

% Begin initialization code - DO NOT EDIT

gui_Singleton = 1;

gui_State = struct('gui_Name',       mfilename, ...

'gui_Singleton',  gui_Singleton, ...

'gui_OpeningFcn', @naozhong_OpeningFcn, ...

'gui_OutputFcn',  @naozhong_OutputFcn, ...

'gui_LayoutFcn',  [] , ...

'gui_Callback',   []);

if nargin && ischar(varargin{1})

gui_State.gui_Callback = str2func(varargin{1});

end

if nargout

[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});

else

gui_mainfcn(gui_State, varargin{:});

end

% End initialization code - DO NOT EDIT

% --- Executes just before naozhong is made visible.

function naozhong_OpeningFcn(hObject, eventdata, handles, varargin)

% This function has no output args, see OutputFcn.

% hObject    handle to figure

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

% varargin   command line arguments to naozhong (see VARARGIN)

% Choose default command line output for naozhong

% UIWAIT makes naozhong wait for user response (see UIRESUME)

% uiwait(handles.figure1);

A=linspace(0,6.3,1000);

x1=8*cos(A);

y1=8*sin(A);

x2=7*cos(A);

y2=7*sin(A);

plot(x1,y1,'b','linewidth',1.4)     %画时钟外圆

hold on

plot(x2,y2,'b','linewidth',3.5)     %画时钟内圆

fill(0.4*cos(A),0.4*sin(A),'r');    %画圆心

axis off

axis([-10 10 -10 10])               %可以使得axis内的图形等比例放大缩小

axis equal                          %使得等轴

title(date,'fontsize',14,'fontweight','bold')                %给定标题名

for k=1:12;

xk=9*cos(-2*pi/12*k+pi/2);

yk=9*sin(-2*pi/12*k+pi/2);

plot([xk/9*8 xk/9*7],[yk/9*8 yk/9*7],'color',[0.3 0.8 0.9])  %该句plot([x1 x2],[y1 y2])可以实现在点[x1 y1]和[x2 y2]之间划线,也就是指向数字的短线

h=text(xk,yk,num2str(k),'fontsize',12,'color',...            %标1,2,3,...12等数字

[0.9 0.3 0.8],'HorizontalAlignment','center');

end

set(handles.edit1,'string',date)

axes(handles.axes1);

htimer=timer('ExecutionMode','fixedRate' ,'TimerFcn',{@TimeUpdate,handles},'Period',1);

start(htimer);

set(hObject,'doublebuffer','on');

% set(hObject, 'DeleteFcn', {@DeleteFcn, htimer}); %设置窗口销毁时的回调函数

handles.output = hObject;

% Update handles structure

guidata(hObject, handles);

function TimeUpdate(hObject,eventdata,handles) %定时器回调函数

ti=clock;

% axes(handles.axes1);

th=-(ti(4)+ti(5)/60+ti(6)/3600)/12*2*pi+pi/2;       %时针当前的角度

xh3=3.0*cos(th);

yh3=3.0*sin(th);                                    %时针末端的点的位置

hh=plot([0  xh3],[0  yh3],'g');                     %如果不是线,而是一个方形指针,则将plot替换为fill即可

tm=-(ti(5)+ti(6)/60)/60*2*pi+pi/2;

xm3=6.0*cos(tm);

ym3=6.0*sin(tm);

hm=plot([0 xm3],[0 ym3],'r');

ts=-(ti(6))/60*2*pi+pi/2;

hs=plot([0 7*cos(ts)],[0 7*sin(ts)],'color','y','linewidth',2);

drawnow;

guidata(hObject, handles);

%

% function DeleteFcn(hObject, eventdata,htimer)          % 窗口关闭的响应函数-停止计时器

%    stop(htimer);

%    delete(htimer); %销毁定时器

%    clear all;

% --- Outputs from this function are returned to the command line.

function varargout = naozhong_OutputFcn(hObject, eventdata, handles)

% varargout  cell array for returning output args (see VARARGOUT);

% hObject    handle to figure

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure

varargout{1} = handles.output;

function edit1_Callback(hObject, eventdata, handles)

% hObject    handle to edit1 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text

%        str2double(get(hObject,'String')) returns contents of edit1 as a double

% --- Executes during object creation, after setting all properties.

function edit1_CreateFcn(hObject, eventdata, handles)

% hObject    handle to edit1 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

%       See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white');

end

每次指针都不动的,是怎么回事啊?

最后

以上就是可靠板栗为你收集整理的matlab的gui倒计时,GUI设计时钟程序中的计时器建立的全部内容,希望文章能够帮你解决matlab的gui倒计时,GUI设计时钟程序中的计时器建立所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(50)

评论列表共有 0 条评论

立即
投稿
返回
顶部