Code covered by the BSD License  

Highlights from
Introduction to MATLAB® Webinar materials

Introduction to MATLAB® Webinar materials

by

 

20 Mar 2007 (Updated )

Presentation and demo materials from the live Webinar "Introduction to MATLAB®" (March 20, 2007)

missingplanesGUI(varargin)
function varargout = missingplanesGUI(varargin)
% MISSINGPLANESGUI M-file for missingplanesGUI.fig
%      MISSINGPLANESGUI, by itself, creates a new MISSINGPLANESGUI or raises the existing
%      singleton*.
%
%      H = MISSINGPLANESGUI returns the handle to a new MISSINGPLANESGUI or the handle to
%      the existing singleton*.
%
%      MISSINGPLANESGUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in MISSINGPLANESGUI.M with the given input arguments.
%
%      MISSINGPLANESGUI('Property','Value',...) creates a new MISSINGPLANESGUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before missingplanesGUI_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to missingplanesGUI_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

% Copyright 2007 The MathWorks, Inc.

% Edit the above text to modify the response to help missingplanesGUI

% Last Modified by GUIDE v2.5 16-Aug-2005 12:00:03

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @missingplanesGUI_OpeningFcn, ...
    'gui_OutputFcn',  @missingplanesGUI_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 missingplanesGUI is made visible.
function missingplanesGUI_OpeningFcn(hObject, eventdata, handles, varargin)		%#ok
% 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 missingplanesGUI (see VARARGIN)

% Choose default command line output for missingplanesGUI
handles.output = hObject;

% Make sure bigscreen is off
try
    bigscreen off
catch
end
set(handles.figure1,'defaultuicontrolfontsize',14); % Large text for datatips

% Add toolbar if it doesn't exist

if ~isfield(handles,'toolbar')
    handles = localCreateToolbar(handles);
end

% Load files if specified
if (length(varargin)==3 && strcmpi(varargin{1},'file') && (2 == exist(varargin{2},'file')) && (2 == exist(varargin{3},'file')))
    handles.filename1 = varargin{2};
    handles.filename2 = varargin{3};

    handles = localLoadFiles(handles);
end



% Update handles structure
guidata(hObject, handles);

% UIWAIT makes missingplanesGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = missingplanesGUI_OutputFcn(hObject, eventdata, handles)		%#ok
% 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 slider movement.
function ThresholdSlider_Callback(hObject, eventdata, handles)		%#ok
% hObject    handle to ThresholdSlider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
threshold = get(handles.ThresholdSlider,'Value');
handles = finddiff(threshold,handles);
guidata(hObject,handles)


% --- Executes during object creation, after setting all properties.
function ThresholdSlider_CreateFcn(hObject, eventdata, handles)		%#ok
% hObject    handle to ThresholdSlider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --------------------------------------------------------------------
function LoadMenu_Callback(hObject, eventdata, handles)		%#ok
% hObject    handle to LoadMenu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

[filename1, pathname1] = uigetfile('*.jpg','Pick first image');
[filename2, pathname2] = uigetfile('*.jpg','Pick second image');
handles.filename1 = fullfile(pathname1, filename1);
handles.filename2 = fullfile(pathname2, filename2);

handles = localLoadFiles(handles);

guidata(hObject,handles)

% --------------------------------------------------------------------
function handles = localLoadFiles(handles)
threshold = get(handles.ThresholdSlider,'Value');
handles = finddiff(threshold,handles);


% --------------------------------------------------------------------
function FileMenu_Callback(hObject, eventdata, handles)		%#ok
% hObject    handle to FileMenu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


function handles = localCreateToolbar(handles)
hToolbar = uitoolbar(handles.figure1);   % Create toolbar

% Load icons
load icons

% Zoom button
hZoom = uitoggletool(hToolbar,'CData',zoomCData, ...
    'TooltipString','Zoom','Tag','Zoom');

% Pan button
hPan = uitoggletool(hToolbar,'CData',panCData, ...
    'TooltipString','Pan','Tag','Pan');


% Datatips
hDatatip = uitoggletool(hToolbar,'CData',datatipCData, ...
    'TooltipString','Identify Data Values','Tag','Datatip');

% Define callbacks
set([hZoom hPan hDatatip],'OnCallback',[mfilename '(''Toggletool_OnCallback'',gcbo,[],guidata(gcbo))'])
set([hZoom hPan hDatatip],'OffCallback',[mfilename '(''Toggletool_OffCallback'',gcbo,[],guidata(gcbo))'])

% Store handles
handles.toolbar = hToolbar;
handles.hZoom = hZoom;
handles.hPan = hPan;
handles.hDatatip = hDatatip;


function Toggletool_OnCallback(hObject, eventdata, handles)		%#ok
% Changing the state automatically calls their offCallback!!


switch get(hObject,'Tag')
    case 'Zoom'
        % Turn off datacursors
        set([handles.hDatatip handles.hPan],'State','off')
        
        % Turn on linked zoom
        linkaxes(handles.axes)
        zoom(handles.figure1,'on')
    case 'Pan'
        % Turn off datacursors
        set([handles.hDatatip handles.hZoom],'State','off')
        
        % Turn on linked pan
        linkaxes(handles.axes)
        pan(handles.figure1,'on')
        
    case 'Datatip'
        % Turn off zoom
        set([handles.hZoom handles.hPan],'State','off')

        obj = datacursormode(handles.figure1);
        set(obj,'Enable','on','DisplayStyle','window')
        set(handles.figure1,'Toolbar','none')
end;

function Toggletool_OffCallback(hObject, eventdata, handles)		%#ok
% Changing the state automatically calls their offCallback!!


switch get(hObject,'Tag')
    case 'Zoom'
        % Turn off linked zoom
        linkaxes(handles.axes,'off')
        zoom(handles.figure1,'off')
    case 'Pan'
        % Turn off linked pan
        linkaxes(handles.axes,'off')
        pan(handles.figure1,'off')
        
    case 'Datatip'
        datacursormode(handles.figure1,'off');
end;

Contact us