timer structure
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
how can I make buttons button1 and button2 can handle even rotatebutton condition "on"?
my code
function varargout = rottest(varargin)
% ROTTEST M-file for rottest.fig
% ROTTEST, by itself, creates a new ROTTEST or raises the existing
% singleton*.
%
% H = ROTTEST returns the handle to a new ROTTEST or the handle to
% the existing singleton*.
%
% ROTTEST('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ROTTEST.M with the given input arguments.
%
% ROTTEST('Property','Value',...) creates a new ROTTEST or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before rottest_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to rottest_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 rottest
% Last Modified by GUIDE v2.5 11-Jun-2011 06:58:14
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @rottest_OpeningFcn, ...
'gui_OutputFcn', @rottest_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 rottest is made visible.
function rottest_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 rottest (see VARARGIN)
% Choose default command line output for rottest
handles.output = hObject;
%just to put something in the axes so we can see it rotating
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes rottest wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = rottest_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;
% --- Executes on button press in rotatebutton.
function rotatebutton_Callback(hObject, eventdata, handles)
% hObject handle to rotatebutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
MyTimer=timerfind('tag','MyTimer');
MyTimerStatus=get(MyTimer,'Running');
if strcmp(MyTimerStatus,'off')
start(MyTimer)
else
stop(MyTimer)
end
function RotImgFcn(a,b)
%this function does the rotation
camorbit(findall(0,'tag','MyAxes'),1,0,'data',[0 0 1]);
% --- Executes when user attempts to close figure1.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% when the user closes the GUI it stops the timer if it is running
% and deletes the timer from memory
MyTimer=timerfind('tag','MyTimer');
MyTimerStatus=get(MyTimer,'Running');
if strcmp(MyTimerStatus,'on')
stop(MyTimer)
end
delete(timerfind('tag','MyTimer')); %delete our timer
%delete(timerfindall) %delete all timer objects
% Hint: delete(hObject) closes the figure
delete(hObject);
% --- Executes on button press in plotbutton.
function plotbutton_Callback(hObject, eventdata, handles)
% hObject handle to plotbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
surf(peaks)
axis vis3d
MyTimer=timer('TimerFcn',@RotImgFcn,'BusyMode','queue','executionmode','fixedspacing','period',0.01);
%tag the timer and axes to have easy access to their handles
set(MyTimer,'tag','MyTimer')
set(handles.axes1,'tag','MyAxes')
% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes1
% --- Executes on button press in xyview.
function button1_Callback(hObject, eventdata, handles)
% hObject handle to xyview (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
view ([0 0])
function button2_Callback(hObject, eventdata, handles)
% hObject handle to xyview (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
view ([90 0])
2 Kommentare
Jan
am 11 Jun. 2011
Does "??? Operation terminated by user during" mean, that you press Ctrl-C? If so, why do you do this?
Antworten (0)
Siehe auch
Kategorien
Mehr zu Programming Utilities finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!