Code covered by the BSD License  

Highlights from
Subplot In A Panle

image thumbnail
from Subplot In A Panle by yang
Function to generate a subplot like result in a panle of GUI or in a Figure

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

% Last Modified by GUIDE v2.5 21-Jun-2013 23:03:49

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @SubplotPanel_OpeningFcn, ...
                   'gui_OutputFcn',  @SubplotPanel_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 SubplotPanel is made visible.
function SubplotPanel_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 SubplotPanel (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


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

%-- Delete old axes handle
% Children=get(handles.uPlot,'children');
% h=[findobj(Children,'Type','axes')];
% if ~isempty(h)
% for i=1:length(h),delete(h(i));end
% end

% for i=1:length(h),axes(h(i));cla reset ;end
% if ~isempty(h),set(h,'Visible','off');end 

%-- Plot Subplot
Layout.Subplot=[2,2];
Layout.Figure=[{[1]},{[2]},{[3,4]}];
handles.AxesHandel=PlotInPanle(handles.uPlot,Layout);

axes(handles.AxesHandel(1));
h=ezplot('x^2');set(h, 'Color', 'm');
title('subplot(2,2,1)')

axes(handles.AxesHandel(2));
ezplot('x^2-y^4');colormap([0 0 1])	;
title('subplot(2,2,2)')

axes(handles.AxesHandel(3));
ezplot3('sin(t)','cos(t)','t',[0,6*pi]);
title('subplot(2,2,[3,4])')




% --- Executes on button press in pSubplot2.
function pSubplot2_Callback(hObject, eventdata, handles)
% hObject    handle to pSubplot2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%-- Delete old axes handle
% Children=get(handles.uPlot,'children');
% h=[findobj(Children,'Type','axes')];
% if ~isempty(h)
% for i=1:length(h),delete(h(i));end
% end

% for i=1:length(h),axes(h(i));cla reset ;end
% if ~isempty(h),set(h,'Visible','off');end 

%-- Plot Subplot
Layout.Subplot=[2,2];
Layout.Figure=[{[1]},{[3]},{[2,4]}];
handles.AxesHandel=PlotInPanle(handles.uPlot,Layout);

axes(handles.AxesHandel(1));
ezpolar('1+cos(t)');
title('subplot(2,2,1)')

axes(handles.AxesHandel(2));
t = 0:pi/50:10*pi;
plot3(sin(t),cos(t),t)
xlabel('sin(t)')
ylabel('cos(t)')
zlabel('t')
grid on
axis square
title('subplot(2,2,3)')

axes(handles.AxesHandel(3));
load count.dat;
y = count(1:10,:); % Loading the dataset creates a variable 'count' 
bar3(y,'detached');
%title('Detached');
title('subplot(2,2,[2,4])')


% --- Executes on button press in pSubplot3.
function pSubplot3_Callback(hObject, eventdata, handles)
% hObject    handle to pSubplot3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%-- Delete old axes handle
% Children=get(handles.uPlot,'children');
% h=[findobj(Children,'Type','axes')];
% if ~isempty(h)
% for i=1:length(h),delete(h(i));end
% end

% for i=1:length(h),axes(h(i));cla reset ;end
% if ~isempty(h),set(h,'Visible','off');end 

%-- Plot Subplot
Layout.Subplot=[1,2];
Layout.Figure=[{[1]},{[2]}];
handles.AxesHandel=PlotInPanle(handles.uPlot,Layout);

axes(handles.AxesHandel(1));
load fisheriris
SL = meas(51:end,1);
SW = meas(51:end,2);
group = species(51:end);
h1 = gscatter(SL,SW,group,'rb','v^',[],'off');
set(h1,'LineWidth',2)
legend('Versicolor','Virginica',...
       'Location','NW')
title('subplot(2,2,1)')   
   
axes(handles.AxesHandel(2));
[X,Y] = meshgrid(linspace(4.5,8),linspace(2,4));
X = X(:); Y = Y(:);
[C,err,P,logp,coeff] = classify([X Y],[SL SW],...
                                group,'quadratic');
hold on;
gscatter(X,Y,C,'rb','.',1,'off');
K = coeff(1,2).const;
L = coeff(1,2).linear; 
Q = coeff(1,2).quadratic;
% Function to compute K + L*v + v'*Q*v for multiple vectors
% v=[x;y]. Accepts x and y as scalars or column vectors.
f = @(x,y) K + [x y]*L + sum(([x y]*Q) .* [x y], 2);

h2 = ezplot(f,[4.5 8 2 4]);
set(h2,'Color','m','LineWidth',2)
axis([4.5 8 2 4])
xlabel('Sepal Length')
ylabel('Sepal Width')
title('subplot(2,2,2)');

Contact us