Matlab learning ------- GUI mouse Event Response (mouse dash instance)

Source: Internet
Author: User

(1) Open guide, add a coordinate axis, and save


(2) Add a mouse RESPONSE event: A mouse-down event, a mouse movement event, and a mouse-loose event


(3) program the corresponding events

Function varargout = guide_m (varargin) % guide_m Matlab code for guide_m.fig % guide_m, by itself, creates a new guide_m or raises the existing % Singleton *. % H = guide_m returns the handle to a new guide_m or the handle to % the existing Singleton *. % guide_m ('callback', hobject, eventdata, handles ,...) callthe local % function named callback in guide_m.m with the given input arguments. % guide_m ('properties', 'value ',...) creates a new guide_m or raises the % existing Singleton *. starting from the left, property value pairs are % applied to the Gui before guide_m_openingfcn gets called. an % unrecognized property name or invalid value makes property application % stop. all inputs are passed to guide_m_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 guide_m % last modified by guide v2.5 25-aug-2014 09:00:37% begin initialization code-do not editgui_singleton = 1; gui_state = struct ('gui _ name', mfilename ,... 'gui _ Singleton ', gui_singleton ,... 'gui _ openingfcn ', @ guide_m_openingfcn ,... 'gui _ outputfcn ', @ guide_m_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 guide_m is made visible. function guide_m_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 guide_m (see varargin) % choose Default command line output for guide_mhandles.output = hobject; % % defines two global variables: Global buttondown pos1; buttondown = []; pos1 = []; % % update handles structureguidata (hobject, handles); % uiwait makes guide_m wait for user response (see uiresume) % uiwait (handles. figure1); % --- outputs from this function are returned to the command line. function varargout = guide_m_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 structurevarargout {1} = handles. output; % --- executes on mouse press over figure background, over a disabled or % --- inactive control, or over an axes background. function figure1_windowbuttondownfcn (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) % % mouse down Event Response global buttondown pos1; if (strcmp (get (GCF, 'selectiontype'), 'normal') % determines the type of the mouse press. The mormal is left-click buttondown = 1; pos1 = get (handles. axes1, 'currentpoint '); % get the end % % --- executes on mouse motion over figure-Snapshot t title and menu. function figure1_windowbuttonmotionfcn (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) % % response to the global buttondown pos1 mouse event; if buttondown = 1 Pos = get (handles. axes1, 'currentpoint'); % get the current position line ([pos1 (1, 1) pos (1, 1)], [pos1 (1, 2) pos (1, 2)], 'linewidth', 4); % dashes pos1 = Pos; % update end % % --- executes on mouse press over figure background, over a disabled or % --- inactive control, or over an axes background. function figure1_windowbuttonupfcn (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) % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%the global buttondown event that the mouse lifted; buttondown = 0; % %
(4) run the test (press the mouse and move the mouse to draw lines)


(5) introduction to some Function Methods

MATLAB callback function


Selectiontype






Matlab learning ------- GUI mouse Event Response (mouse dash instance)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.