I have several functions in an M File:
function myfun1myfun2endfunction myfun2myfun3end
How can I stop executing a specific function and exit the script?
exitm-file
function myfun1myfun2endfunction myfun2myfun3end
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 04-Jun-2011 18:27:20
% 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});endif 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;spy %just to put something in the axes so we can see it rotating
MyTimer=timer('TimerFcn',@RotImgFcn,'BusyMode','queue','executionmode','fixedspacing','period',0.5);%tag the timer and axes to have easy access to their handles
set(MyTimer,'tag','MyTimer')set(handles.axes1,'tag','MyAxes')% 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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)% hObject handle to pushbutton1 (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)elsestop(MyTimer)endfunction 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)enddelete(timerfind('tag','MyTimer')); %delete our timer
%delete(timerfindall) %delete all timer objects
% Hint: delete(hObject) closes the figure
delete(hObject);
Best Answer