MATLAB: How to highlight UI-objects in flashing way in MATLAB 7.5 (R2007b)

dwhhgdoneMATLAB

I would like to be able to highlight UI-objects in a flashing manner.

Best Answer

There is no direct way for the highlighting of an UI-objects in flashing way, but it is possible to implement this feature using the Timer-Function. Take a look on the following function FLASH. Please copy the content into the editor and save all as FLASH.M file
function T = flash(obj,ftr,col1,col2,N)
% FLASH allows the highlighting of an UI-Object in a flashing way
% T = flash(h,feature,color1,color2,N)
% Input-Parameters
% h - handle of the object which should be highlighted
% feature - object feature, e.g. Color, ForegroundColor, BackgroundColor
% color1 - first color
% color2 - second color
% N - the count of flashs (Inf for endless flashing)
%
% Output-Parameter
% T - timer handle (necessary if N = Inf)
%




% Example 1
% x = [0:0.01:2*pi];
% h1 = plot(x,sin(x),'r');
% flash(h1,'Color',[1 0 0],[1 1 1],11)
%
% Example 2
% h2 = uicontrol('string','ok')

% flash(h2,'BackgroundColor',[1 0 0],[.8 .8 .8],10)
%
% Example 3
% h2 = uicontrol('string','ok')
% T = flash(h2,'BackgroundColor',[1 0 0],[.8 .8 .8],Inf)
% to stop the endless flashing use
% stop(T)
T = timer('TimerFcn',{@flash_fcn,obj,ftr,col1,col2}, ...
'Period',0.25, ...
'BusyMode','queue', ...
'ExecutionMode','fixedDelay', ...
'TasksToExecute',N, ...
'ObjectVisibility','off', ...
'StopFcn',{@flash_stop});
start(T);
%
function flash_stop(T,cnc)
delete(T)
%
function flash_fcn(T,cnc,obj,ftr,col1,col2)
T.TimerFcn = {@flash_fcn,obj,ftr,col2,col1};
set(obj,ftr,col1)