%% === T_ring.m (注意使用原始文件名) ======
function [ ] = T_ring( obj, event , T_event ) %UNTITLED Summary of this function goes here % Detailed explanation goes here
%% === save the content of cell - T_event ===== msg = T_event{1,1} ;
% disp(msg) ; % === test code ========
msgbox(msg, '你有一个闹铃提醒') ;
%% === 这是matlab 自带的铃声,其他的铃声程序可以在网上找 === for i = 1:5
load splat ; sound(y, Fs) ; end end
%% === 子文件 计时程序(注:这不是一个函数文件) === %% === calc_time.m (注意使用原始文件名) ======
%% === create a figure ========== h1 = figure( 'MenuBar' , 'none' ,... 'Color' , 'white' ,...
'NumberTitle' , 'off' ,...
'units','normalized' , 'position', [0.35 0.4 0.3 0.2], ... 'Name' , 'Calc_time' ) ;
%% ===
h1_text = uicontrol('parent', h1, ... 'BackgroundColor', [1 0.8 0.4], ... 'fontname' , 'Verdana' ,... 'fontsize' , 20 ,... 'style', 'text', ...
'horizontal', 'center', ...
'units','normalized' , 'position', [0.15 0.5 0.7 0.3], ... 'string', '0 : 0 : 0.0' );
%% ===
h1_button_start = uicontrol('parent', h1, ...
6
'BackgroundColor', [1 0.8 0.4], ... 'fontname' , 'Verdana' ,... 'fontsize' , 12 ,...
'style', 'pushbutton', ... 'horizontal', 'center', ...
'units','normalized' , 'position', [0.15 0.2 0.2 0.2], ... 'callback' , [' k=0 ;'] ,... 'string', 'start' );
%% ===
h1_button_stop = uicontrol('parent', h1, ... 'BackgroundColor', [1 0.8 0.4], ... 'fontname' , 'Verdana' ,... 'fontsize' , 12 ,...
'horizontal', 'center', ...
'units','normalized' , 'position', [0.40 0.2 0.2 0.2], ... 'callback' , [... ' k=1 ; , '] ,... 'string', 'stop' ) ;
%% ===
h1_button_reset = uicontrol('parent', h1, ... 'BackgroundColor', [1 0.8 0.4], ... 'fontname' , 'Verdana' ,... 'fontsize' , 12 ,...
'horizontal', 'center', ...
'units','normalized' , 'position', [0.65 0.2 0.2 0.2], ... 'callback' , [... ' k=2 ; , '] ,... 'string', 'reset' ) ;
%% === k = 2 ;
while ishandle(h1)
if ( 0 == k )
t_that = clock ;
while ishandle(h1)
t_this = clock ; % ==
7
if ( t_this(6) >= t_that(6) )
t_second = t_this(6) - t_that(6) ; else
if ( t_this(5) > t_that(5) ) t_this(5) = t_this(5) - 1 ;
t_second = t_this(6) + 60 - t_that(6) ; else
t_this(4) = t_this(4) - 1 ; t_this(5) = t_this(5) + 59 ;
t_second = t_this(6) + 60 - t_that(6) ; end end % ==
if ( t_this(5) >= t_that(5) )
t_minute = t_this(5) - t_that(5) ; else
t_this(4) = t_this(4) - 1 ;
t_minute = t_this(5) + 60 - t_that(5) ; end % ==
t_hour = t_this(4) - t_that(4) ; % ==
set( h1_text , 'String' , [num2str(t_hour) ' : ' num2str(t_minute) ' : ' num2str(t_second)] ) ;
pause( 0.1 ) ; % === ! important pause in inside while ======= % ==
if ( k == 1 ) break ; end
if ( k == 2 )
set( h1_text , 'String' , '0 : 0 : 0.0' ) ; break ; end
end %=== close inside while ==========
8
end
if ( k == 2 )
set( h1_text , 'String' , '0 : 0 : 0.0' ) ; end
pause( 0.1 ) ; % === ! important pause in outside while ===========
end %=== close outside while ==========
摘要
使用matlan的画图函数,如:plot 、fill 等,设计了一个简约的圆形时钟GUI,并使用图形句柄实现了动态显示时间,自带图像背景,具有闹钟功能。
关键词: matlab时钟 matlab闹钟 clock timer matlab GUI背景 matlab计时
1. 工具与函数
MATLAB
MATLAB是matrix&laboratory两个词的组合,意为矩阵工厂(矩阵实验室)。是由美国mathworks公司发布的主要面对科学计算、可视化以及交互式程序设计的高科技计算环境。它将数值分析、矩阵计算、科学数据可视化以及非线性动态系统的建模和仿真等诸多强大功能集成在一个易于使用的视窗环境中,为科学研究、工程设计以及必须进行有效数值计算的众多科学领域提供了一种全面的解决方案,并在很大程度上摆脱了传统非交互式程序设计语言(如C、Fortran)的编辑模式,代表了当今国际科学计算软件的先进水平。
MATLAB和Mathematica、Maple并称为三大数学软件。它在数学类科技应用软件中在数值计算方面首屈一指。MATLAB可以进行矩阵运算、绘制函数和数据、实现算法、创建用户界面、连接其他编程语言的程序等,主要应用于工程计算、控制设计、信号处理与通讯、图像处理、信号检测、金融建模设计与分析等领域。 clock
clock 在matlab中用于获取系统时间,返回一个数组,保存系统时间,保存格式为 [年 月 日 时 分 秒] 。
>>clock ans = 1.0e+03 *
2.0150 0.0060 0.0140 0.0170 0.0490 0.0175
9
plot
绘图函数plot,根据不同的坐标参数可以二维平面上绘制出不同的曲线。 语法:plot( X, Y, LineSpec )
X, Y为同维向量时,绘制以X,Y元素为横,纵坐标的一条曲线,LineSpec,用于指出线条的类型、标记符号和颜色。 figure
figure创建一个图形窗口,用法如下:
figure ; 创建一个图形窗口,所有属性皆为默认。
figure( '属性' , '属性值' ) ; 创建一个用户自定义的图形窗口。
h = figure( '属性' , '属性值' ) ; 创建一个图形窗口,并返回窗口的句柄。 uicontrol
Uicontrol是user interface control 的缩写(用户界面控制)。MATLAB控制框,又称uicontrol,与窗口管理器所用的函数十分相似。它们是图形对象,可以放置在MATLAB的图形窗中的任何位置并用鼠标激活。MATLAB的 uicontrol包括按钮、滑标、文本框及 弹出式菜单。
语法:H=uicontrol((Hf_fig, ' 属性 ' ,属性值,...)
其中,H是由函数uicontrol生成uicontrol对象的句柄,Hf_fig是父对象的句柄,它必须是图形,属性 ' Style ' 决定了所建控制框的类型。 ' Callback ' 属性值是当控制框激活时,传给eval在命令窗口空间执行的MATLAB字符串。 timer
鉴于Matlab 中缺乏多线程机制,使用Timer 无疑是一个很重要的工具,Matlab中Timer(定时器)是一个Java对象。
语法: t=timer( '属性' , 属性值 ) ;
属性:TimerFcn:Timer执行的函数,属性值 ‘@function_name’ ,就是你定义的函数名。
ExecutionMode:执行模式,决定定时器对象如何安排定时事件。属性值:'singleShot'(默认值) 、'fixedDelay'、 'fixedRate'、 'fixedSpacing' 。
Period:定时器触发周期(默认值为1s,数据类型double,最小定时时长0.001)。 StartDelay:指定从定时器开始到第一次执行callback函数的延时时长(数据类型double,值的范围:大于0的数,默认值为0)[即若加此属性,第一次定时时间为Period + StartDelay]。
StartFcn:定时器开启时的回调函数。 StopFcn:定时器停止时的回调函数
startat ( OBJ, [Y, M, D, H, MI, S] ) :在 [Y, M, D, H, MI, S] 时间上启动timer,Y:年,M:月, D:日, H:时, MI:分, S:秒。
10