123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766 |
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
- "http://www.w3.org/TR/REC-html40/loose.dtd">
- <html>
- <head>
- <title>Description of auto_classify</title>
- <meta name="keywords" content="auto_classify">
- <meta name="description" content="AUTO_CLASSIFY M-file for auto_classify.fig">
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
- <meta name="generator" content="m2html © 2005 Guillaume Flandin">
- <meta name="robots" content="index, follow">
- <link type="text/css" rel="stylesheet" href="../../m2html.css">
- <script type="text/javascript">
- if (top.frames.length == 0) { top.location = "../../index.html"; };
- </script>
- </head>
- <body>
- <a name="_top"></a>
- <!-- ../menu.html chronux_2_10 --><!-- menu.html wave_browser -->
- <h1>auto_classify
- </h1>
- <h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
- <div class="box"><strong>AUTO_CLASSIFY M-file for auto_classify.fig</strong></div>
- <h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
- <div class="box"><strong>function varargout = auto_classify(varargin) </strong></div>
- <h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
- <div class="fragment"><pre class="comment"> AUTO_CLASSIFY M-file for auto_classify.fig
- AUTO_CLASSIFY, by itself, creates a new AUTO_CLASSIFY or raises the existing
- singleton*.
- H = AUTO_CLASSIFY returns the handle to a new AUTO_CLASSIFY or the handle to
- the existing singleton*.
- AUTO_CLASSIFY('CALLBACK',hObject,eventData,handles,...) calls the local
- function named CALLBACK in AUTO_CLASSIFY.M with the given input arguments.
- AUTO_CLASSIFY('Property','Value',...) creates a new AUTO_CLASSIFY or raises the
- existing singleton*. Starting from the left, property value pairs are
- applied to the GUI before auto_classify_OpeningFunction gets called. An
- unrecognized property name or invalid value makes property application
- stop. All inputs are passed to auto_classify_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</pre></div>
- <!-- crossreference -->
- <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
- This function calls:
- <ul style="list-style-image:url(../../matlabicon.gif)">
- <li><a href="../../chronux_2_10/fly_track/videoIO/videoIO_2006a/@videoReader/close.html" class="code" title="function vr = close(vr)">close</a> VR=CLOSE(VR)</li><li><a href="../../chronux_2_10/fly_track/videoIO/videoIO_2006a/@videoWriter/close.html" class="code" title="function vw = close(vw)">close</a> VW=CLOSE(VW)</li><li><a href="../../chronux_2_10/fly_track/videoIO/videoIO_2006b/@videoReader/close.html" class="code" title="function vr = close(vr)">close</a> VR=CLOSE(VR)</li><li><a href="../../chronux_2_10/fly_track/videoIO/videoIO_2006b/@videoWriter/close.html" class="code" title="function vw = close(vw)">close</a> VW=CLOSE(VW)</li><li><a href="../../chronux_2_10/fly_track/videoIO/videoIO_2007a/@videoReader/close.html" class="code" title="function vr = close(vr)">close</a> VR=CLOSE(VR)</li><li><a href="../../chronux_2_10/fly_track/videoIO/videoIO_2007a/@videoWriter/close.html" class="code" title="function vw = close(vw)">close</a> VW=CLOSE(VW)</li></ul>
- This function is called by:
- <ul style="list-style-image:url(../../matlabicon.gif)">
- <li><a href="classify_spectra.html" class="code" title="function varargout = classify_spectra(varargin)">classify_spectra</a> CLASSIFY_SPECTRA M-file for classify_spectra.fig</li></ul>
- <!-- crossreference -->
- <h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
- <ul style="list-style-image:url(../../matlabicon.gif)">
- <li><a href="#_sub1" class="code">function auto_classify_OpeningFcn(hObject, eventdata, handles, varargin)</a></li><li><a href="#_sub2" class="code">function varargout = auto_classify_OutputFcn(hObject, eventdata, handles)</a></li><li><a href="#_sub3" class="code">function clusters = clusterdata(X,k,dmeasure)</a></li><li><a href="#_sub4" class="code">function AutoClassifyButton_Callback(hObject, eventdata, handles)</a></li><li><a href="#_sub5" class="code">function CancelButton_Callback(hObject, eventdata, handles)</a></li><li><a href="#_sub6" class="code">function AcceptButton_Callback(hObject, eventdata, handles)</a></li><li><a href="#_sub7" class="code">function CepstralEdit_Callback(hObject, eventdata, handles)</a></li><li><a href="#_sub8" class="code">function CepstralEdit_CreateFcn(hObject, eventdata, handles)</a></li><li><a href="#_sub9" class="code">function MinClusters_Callback(hObject, eventdata, handles)</a></li><li><a href="#_sub10" class="code">function MinClusters_CreateFcn(hObject, eventdata, handles)</a></li><li><a href="#_sub11" class="code">function MaxClusters_Callback(hObject, eventdata, handles)</a></li><li><a href="#_sub12" class="code">function MaxClusters_CreateFcn(hObject, eventdata, handles)</a></li><li><a href="#_sub13" class="code">function TransformPopupMenu_Callback(hObject, eventdata, handles)</a></li><li><a href="#_sub14" class="code">function TransformPopupMenu_CreateFcn(hObject, eventdata, handles)</a></li><li><a href="#_sub15" class="code">function KClasses_Callback(hObject, eventdata, handles)</a></li><li><a href="#_sub16" class="code">function KClasses_CreateFcn(hObject, eventdata, handles)</a></li><li><a href="#_sub17" class="code">function CepstralPopupMenu_Callback(hObject, eventdata, handles)</a></li><li><a href="#_sub18" class="code">function CepstralPopupMenu_CreateFcn(hObject, eventdata, handles)</a></li><li><a href="#_sub19" class="code">function RangeSpecify_Callback(hObject, eventdata, handles)</a></li><li><a href="#_sub20" class="code">function DistancePopupMenu_Callback(hObject, eventdata, handles)</a></li><li><a href="#_sub21" class="code">function DistancePopupMenu_CreateFcn(hObject, eventdata, handles)</a></li><li><a href="#_sub22" class="code">function DiagnosticCheckbox_Callback(hObject, eventdata, handles)</a></li><li><a href="#_sub23" class="code">function pcaplot(matrix2classify,classification)</a></li><li><a href="#_sub24" class="code">function classifymatrix = madnormalize(classifymatrix, cols2normalize)</a></li><li><a href="#_sub25" class="code">function c=cluster_aylin(p1,p2);</a></li><li><a href="#_sub26" class="code">function [p1,p2]=hneighbors(e);</a></li><li><a href="#_sub27" class="code">function classification = cluster_hierarchical(matrix2classify)</a></li><li><a href="#_sub28" class="code">function HierarchicalRadioButton_Callback(hObject, eventdata, handles)</a></li><li><a href="#_sub29" class="code">function KmeansRadioButton_Callback(hObject, eventdata, handles)</a></li><li><a href="#_sub30" class="code">function SegLenWeight_Callback(hObject, eventdata, handles)</a></li><li><a href="#_sub31" class="code">function SegLenWeight_CreateFcn(hObject, eventdata, handles)</a></li></ul>
- <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
- <div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function varargout = auto_classify(varargin)</a>
- 0002 <span class="comment">% AUTO_CLASSIFY M-file for auto_classify.fig</span>
- 0003 <span class="comment">% AUTO_CLASSIFY, by itself, creates a new AUTO_CLASSIFY or raises the existing</span>
- 0004 <span class="comment">% singleton*.</span>
- 0005 <span class="comment">%</span>
- 0006 <span class="comment">% H = AUTO_CLASSIFY returns the handle to a new AUTO_CLASSIFY or the handle to</span>
- 0007 <span class="comment">% the existing singleton*.</span>
- 0008 <span class="comment">%</span>
- 0009 <span class="comment">% AUTO_CLASSIFY('CALLBACK',hObject,eventData,handles,...) calls the local</span>
- 0010 <span class="comment">% function named CALLBACK in AUTO_CLASSIFY.M with the given input arguments.</span>
- 0011 <span class="comment">%</span>
- 0012 <span class="comment">% AUTO_CLASSIFY('Property','Value',...) creates a new AUTO_CLASSIFY or raises the</span>
- 0013 <span class="comment">% existing singleton*. Starting from the left, property value pairs are</span>
- 0014 <span class="comment">% applied to the GUI before auto_classify_OpeningFunction gets called. An</span>
- 0015 <span class="comment">% unrecognized property name or invalid value makes property application</span>
- 0016 <span class="comment">% stop. All inputs are passed to auto_classify_OpeningFcn via varargin.</span>
- 0017 <span class="comment">%</span>
- 0018 <span class="comment">% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one</span>
- 0019 <span class="comment">% instance to run (singleton)".</span>
- 0020 <span class="comment">%</span>
- 0021 <span class="comment">% See also: GUIDE, GUIDATA, GUIHANDLES</span>
- 0022
- 0023 <span class="comment">% Copyright 2002-2003 The MathWorks, Inc.</span>
- 0024
- 0025 <span class="comment">% Edit the above text to modify the response to help auto_classify</span>
- 0026
- 0027 <span class="comment">% Last Modified by GUIDE v2.5 21-Jun-2006 00:34:13</span>
- 0028
- 0029 <span class="comment">% Begin initialization code - DO NOT EDIT</span>
- 0030 gui_Singleton = 1;
- 0031 gui_State = struct(<span class="string">'gui_Name'</span>, mfilename, <span class="keyword">...</span>
- 0032 <span class="string">'gui_Singleton'</span>, gui_Singleton, <span class="keyword">...</span>
- 0033 <span class="string">'gui_OpeningFcn'</span>, @<a href="#_sub1" class="code" title="subfunction auto_classify_OpeningFcn(hObject, eventdata, handles, varargin)">auto_classify_OpeningFcn</a>, <span class="keyword">...</span>
- 0034 <span class="string">'gui_OutputFcn'</span>, @<a href="#_sub2" class="code" title="subfunction varargout = auto_classify_OutputFcn(hObject, eventdata, handles)">auto_classify_OutputFcn</a>, <span class="keyword">...</span>
- 0035 <span class="string">'gui_LayoutFcn'</span>, [] , <span class="keyword">...</span>
- 0036 <span class="string">'gui_Callback'</span>, []);
- 0037 <span class="keyword">if</span> nargin && ischar(varargin{1})
- 0038 gui_State.gui_Callback = str2func(varargin{1});
- 0039 <span class="keyword">end</span>
- 0040
- 0041 <span class="keyword">if</span> nargout
- 0042 [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
- 0043 <span class="keyword">else</span>
- 0044 gui_mainfcn(gui_State, varargin{:});
- 0045 <span class="keyword">end</span>
- 0046 <span class="comment">% End initialization code - DO NOT EDIT</span>
- 0047
- 0048
- 0049 <span class="comment">% --- Executes just before auto_classify is made visible.</span>
- 0050 <a name="_sub1" href="#_subfunctions" class="code">function auto_classify_OpeningFcn(hObject, eventdata, handles, varargin)</a>
- 0051 <span class="comment">% This function has no output args, see OutputFcn.</span>
- 0052 <span class="comment">% hObject handle to figure</span>
- 0053 <span class="comment">% eventdata reserved - to be defined in a future version of MATLAB</span>
- 0054 <span class="comment">% handles structure with handles and user data (see GUIDATA)</span>
- 0055 <span class="comment">% varargin command line arguments to auto_classify (see VARARGIN)</span>
- 0056
- 0057 <span class="comment">% input parameters</span>
- 0058
- 0059 <span class="keyword">if</span> isempty(varargin)
- 0060 handles.matrix2classify = [];
- 0061 handles.ncepstral = 5;
- 0062 <span class="keyword">else</span>
- 0063 handles.matrix2classify = varargin{1};
- 0064 handles.ncepstral = varargin{2};
- 0065 <span class="keyword">end</span>
- 0066
- 0067 handles.distancemeasure = <span class="string">'sqEuclidean'</span>;
- 0068
- 0069 handles.cluster_method = <span class="string">'kmeans'</span>;
- 0070
- 0071 set(handles.CepstralPopupMenu,<span class="string">'String'</span>,num2str([0:handles.ncepstral]'));
- 0072 set(handles.CepstralPopupMenu,<span class="string">'Value'</span>,handles.ncepstral); <span class="comment">%handles.ncepstral +1 );</span>
- 0073 <span class="comment">% set(handles.CepstralPopupMenu,'Value',handles.ncepstral-1);</span>
- 0074
- 0075 <span class="comment">% Choose default command line output for auto_classify</span>
- 0076 <span class="comment">% handles.output = hObject;</span>
- 0077
- 0078 <span class="comment">% Update handles structure</span>
- 0079 guidata(hObject, handles);
- 0080
- 0081 <span class="comment">% UIWAIT makes auto_classify wait for user response (see UIRESUME)</span>
- 0082 <span class="comment">% uiwait(handles.figure1);</span>
- 0083
- 0084 uiwait(handles.figure1);
- 0085
- 0086 <span class="comment">% --- Outputs from this function are returned to the command line.</span>
- 0087 <a name="_sub2" href="#_subfunctions" class="code">function varargout = auto_classify_OutputFcn(hObject, eventdata, handles) </a>
- 0088 <span class="comment">% varargout cell array for returning output args (see VARARGOUT);</span>
- 0089 <span class="comment">% hObject handle to figure</span>
- 0090 <span class="comment">% eventdata reserved - to be defined in a future version of MATLAB</span>
- 0091 <span class="comment">% handles structure with handles and user data (see GUIDATA)</span>
- 0092
- 0093 <span class="comment">% Get default command line output from handles structure</span>
- 0094 varargout{1} = handles.output;
- 0095
- 0096 <a href="../../chronux_2_10/fly_track/videoIO/videoIO_2006a/@videoReader/close.html" class="code" title="function vr = close(vr)">close</a>;
- 0097
- 0098 <a name="_sub3" href="#_subfunctions" class="code">function clusters = clusterdata(X,k,dmeasure)</a>
- 0099 <span class="comment">% A wrapper function for clustering</span>
- 0100
- 0101 <span class="keyword">try</span>
- 0102 clusters = kmeans(X,k,<span class="string">'distance'</span>,dmeasure,<span class="string">'EmptyAction'</span>,<span class="string">'singleton'</span>,<span class="string">'replicates'</span>,30);
- 0103 <span class="keyword">catch</span>
- 0104 clusters = k;
- 0105 <span class="keyword">end</span>
- 0106
- 0107 <span class="comment">% --- Executes on button press in AutoClassifyButton.</span>
- 0108 <a name="_sub4" href="#_subfunctions" class="code">function AutoClassifyButton_Callback(hObject, eventdata, handles)</a>
- 0109 <span class="comment">% hObject handle to AutoClassifyButton (see GCBO)</span>
- 0110 <span class="comment">% eventdata reserved - to be defined in a future version of MATLAB</span>
- 0111 <span class="comment">% handles structure with handles and user data (see GUIDATA)</span>
- 0112
- 0113 set(handles.AcceptButton,<span class="string">'Enable'</span>,<span class="string">'off'</span>);
- 0114 guidata(gcbo,handles);
- 0115
- 0116 cncepstral = get(handles.CepstralPopupMenu,<span class="string">'Value'</span>);
- 0117
- 0118 matrix2classify = handles.matrix2classify;
- 0119 matrix2classify = <a href="#_sub24" class="code" title="subfunction classifymatrix = madnormalize(classifymatrix, cols2normalize)">madnormalize</a>(matrix2classify,1); <span class="comment">% normalize the columns</span>
- 0120 matrix2classify = matrix2classify(:,1:cncepstral+1); <span class="comment">% include the cepstral coefficients that you want</span>
- 0121
- 0122 <span class="keyword">if</span> length(matrix2classify(1,:)) > 3
- 0123 matrix2classify = matrix2classify(:,[1,3:cncepstral+1]); <span class="comment">% exclude the first cepestral coefficient</span>
- 0124 <span class="keyword">end</span>
- 0125
- 0126 <span class="keyword">try</span>
- 0127 segweight = str2num(get(handles.SegLenWeight,<span class="string">'String'</span>));
- 0128 <span class="keyword">catch</span>
- 0129 segweight = 1;
- 0130 set(handles.SegLenWeight,<span class="string">'String'</span>,<span class="string">'1'</span>);
- 0131 <span class="keyword">end</span>
- 0132
- 0133 <span class="comment">% Weight the segment lengths by square root of the weight</span>
- 0134 matrix2classify(:,1) = matrix2classify(:,1)*sqrt(segweight);
- 0135
- 0136 <span class="comment">% Other weightings can be added here but the cepestral coefficients have a</span>
- 0137 <span class="comment">% natural exponential decline which acts a weighting</span>
- 0138
- 0139 <span class="comment">%Handle transformations to segment length</span>
- 0140
- 0141 contents = get(handles.TransformPopupMenu,<span class="string">'String'</span>);
- 0142 value = get(handles.TransformPopupMenu,<span class="string">'Value'</span>);
- 0143
- 0144 <span class="keyword">switch</span> contents{value}
- 0145 <span class="keyword">case</span> <span class="string">'None'</span>
- 0146 matrix2classify = matrix2classify;
- 0147 <span class="keyword">case</span> <span class="string">'Exclude'</span>
- 0148 matrix2classify = matrix2classify(:,2:length(matrix2classify(1,:)));
- 0149 <span class="keyword">case</span> <span class="string">'Log'</span>
- 0150 matrix2classify(:,1) = log(matrix2classify(:,1));
- 0151 <span class="keyword">case</span> <span class="string">'Exp'</span>
- 0152 matrix2classify(:,1) = exp(matrix2classify(:,1));
- 0153 <span class="keyword">end</span>
- 0154
- 0155 <span class="keyword">if</span> length(matrix2classify(1,:)) == 0 <span class="comment">% matrix to classify has no information</span>
- 0156 <span class="keyword">return</span>
- 0157 <span class="keyword">end</span>
- 0158
- 0159 rangestate = get(handles.RangeSpecify,<span class="string">'Value'</span>);
- 0160 diagnosticstate = get(handles.DiagnosticCheckbox,<span class="string">'Value'</span>);
- 0161
- 0162 <span class="keyword">if</span> strcmp(handles.cluster_method,<span class="string">'hierarchical'</span>)
- 0163 handles.classification = <a href="#_sub27" class="code" title="subfunction classification = cluster_hierarchical(matrix2classify)">cluster_hierarchical</a>(matrix2classify);
- 0164 nclusters = length(unique(handles.classification)) - 1;
- 0165 set(handles.KClasses,<span class="string">'String'</span>,nclusters);
- 0166
- 0167 <span class="keyword">if</span> diagnosticstate
- 0168 <a href="#_sub23" class="code" title="subfunction pcaplot(matrix2classify,classification)">pcaplot</a>(matrix2classify,handles.classification);
- 0169 <span class="keyword">end</span>
- 0170
- 0171 <span class="keyword">else</span> <span class="keyword">if</span> strcmp(handles.cluster_method, <span class="string">'kmeans'</span>)
- 0172
- 0173 <span class="keyword">if</span> not(rangestate)
- 0174
- 0175 kclassstr = get(handles.KClasses,<span class="string">'String'</span>);
- 0176
- 0177 <span class="keyword">if</span> not(isempty(kclassstr))
- 0178 <span class="keyword">try</span>
- 0179 nclasses = str2num(kclassstr);
- 0180 <span class="keyword">catch</span>
- 0181 <span class="keyword">return</span>;
- 0182 <span class="keyword">end</span>
- 0183
- 0184 classification = <a href="#_sub3" class="code" title="subfunction clusters = clusterdata(X,k,dmeasure)">clusterdata</a>(matrix2classify,nclasses,handles.distancemeasure);<span class="comment">% this can be changed to a different clustering algorithm</span>
- 0185
- 0186 <span class="comment">% clusterdata shows how a clustering algorithm can be hooked in where the number of</span>
- 0187 <span class="comment">% classes need to be assigned.</span>
- 0188
- 0189 <span class="keyword">if</span> length(classification) == 1
- 0190 msgbox(<span class="string">'Error in clustering. Try changing the number of target clusters or rerunning.'</span>);
- 0191 <span class="keyword">else</span>
- 0192 <span class="keyword">if</span> diagnosticstate
- 0193 figure();
- 0194 [silh h] = silhouette(matrix2classify,classification);
- 0195 <a href="#_sub23" class="code" title="subfunction pcaplot(matrix2classify,classification)">pcaplot</a>(matrix2classify,classification);
- 0196 <span class="keyword">end</span>
- 0197 handles.classification = classification;
- 0198 <span class="keyword">end</span>
- 0199 <span class="keyword">else</span>
- 0200 <span class="keyword">return</span>;
- 0201 <span class="keyword">end</span>
- 0202 <span class="keyword">else</span>
- 0203 <span class="keyword">try</span>
- 0204 minclust = str2num(get(handles.MinClusters,<span class="string">'String'</span>));
- 0205 <span class="keyword">catch</span>
- 0206 <span class="keyword">return</span>;
- 0207 <span class="keyword">end</span>
- 0208 <span class="keyword">try</span>
- 0209 maxclust = str2num(get(handles.MaxClusters,<span class="string">'String'</span>));
- 0210 <span class="keyword">catch</span>
- 0211 <span class="keyword">return</span>;
- 0212 <span class="keyword">end</span>
- 0213
- 0214 resultsclust = cell((1+ maxclust)-minclust,1);
- 0215
- 0216 hw = waitbar(0,<span class="string">'Clustering data set '</span>);
- 0217 <span class="keyword">for</span> i = 1:(1+maxclust)-minclust
- 0218 resultsclust{i} = <a href="#_sub3" class="code" title="subfunction clusters = clusterdata(X,k,dmeasure)">clusterdata</a>(matrix2classify,minclust + (i-1),handles.distancemeasure);
- 0219 <span class="keyword">if</span> length(resultsclust{i}) == 1
- 0220 msgbox([<span class="string">'Clustering failed at '</span> num2str(resultsclust{i}) <span class="string">' clusters. Try changing the range of clusters or rerunning.'</span>]);
- 0221 <span class="keyword">return</span>;
- 0222 <span class="keyword">end</span>
- 0223 waitbar(i/(1+maxclust-minclust));
- 0224 <span class="keyword">end</span>
- 0225 <a href="../../chronux_2_10/fly_track/videoIO/videoIO_2006a/@videoReader/close.html" class="code" title="function vr = close(vr)">close</a>(hw);
- 0226
- 0227 silhmean = zeros((1+ maxclust)-minclust,1);
- 0228
- 0229 <span class="keyword">for</span> i = 1:1+(maxclust)-minclust
- 0230
- 0231 <span class="keyword">if</span> diagnosticstate
- 0232 figure();
- 0233 [silh h] = silhouette(matrix2classify,resultsclust{i});
- 0234 <a href="#_sub23" class="code" title="subfunction pcaplot(matrix2classify,classification)">pcaplot</a>(matrix2classify,resultsclust{i});
- 0235 <span class="keyword">else</span>
- 0236 silh = silhouette(matrix2classify,resultsclust{i});
- 0237 <span class="keyword">end</span>
- 0238
- 0239 silhmean(i) = mean(silh);
- 0240 <span class="keyword">end</span>
- 0241
- 0242 [x I] = max(silhmean);
- 0243 handles.classification = resultsclust{I(1)};
- 0244
- 0245 set(handles.KClasses,<span class="string">'String'</span>,num2str(minclust + (I(1)-1)));
- 0246 <span class="keyword">end</span>
- 0247 <span class="keyword">end</span>
- 0248 <span class="keyword">end</span>
- 0249
- 0250
- 0251 set(handles.AcceptButton,<span class="string">'Enable'</span>,<span class="string">'on'</span>);
- 0252
- 0253 guidata(gcbo,handles);
- 0254
- 0255 <span class="comment">% --- Executes on button press in CancelButton.</span>
- 0256 <a name="_sub5" href="#_subfunctions" class="code">function CancelButton_Callback(hObject, eventdata, handles)</a>
- 0257 <span class="comment">% hObject handle to CancelButton (see GCBO)</span>
- 0258 <span class="comment">% eventdata reserved - to be defined in a future version of MATLAB</span>
- 0259 <span class="comment">% handles structure with handles and user data (see GUIDATA)</span>
- 0260
- 0261 handles.output = 0;
- 0262 guidata(hObject,handles);
- 0263 uiresume(handles.figure1);
- 0264
- 0265 <span class="comment">% --- Executes on button press in AcceptButton.</span>
- 0266 <a name="_sub6" href="#_subfunctions" class="code">function AcceptButton_Callback(hObject, eventdata, handles)</a>
- 0267 <span class="comment">% hObject handle to AcceptButton (see GCBO)</span>
- 0268 <span class="comment">% eventdata reserved - to be defined in a future version of MATLAB</span>
- 0269 <span class="comment">% handles structure with handles and user data (see GUIDATA)</span>
- 0270
- 0271 handles.output = handles.classification;
- 0272 guidata(hObject,handles);
- 0273 uiresume(handles.figure1);
- 0274
- 0275
- 0276 <a name="_sub7" href="#_subfunctions" class="code">function CepstralEdit_Callback(hObject, eventdata, handles)</a>
- 0277 <span class="comment">% hObject handle to CepstralEdit (see GCBO)</span>
- 0278 <span class="comment">% eventdata reserved - to be defined in a future version of MATLAB</span>
- 0279 <span class="comment">% handles structure with handles and user data (see GUIDATA)</span>
- 0280
- 0281 <span class="comment">% Hints: get(hObject,'String') returns contents of CepstralEdit as text</span>
- 0282 <span class="comment">% str2double(get(hObject,'String')) returns contents of CepstralEdit as a double</span>
- 0283
- 0284
- 0285 <span class="comment">% --- Executes during object creation, after setting all properties.</span>
- 0286 <a name="_sub8" href="#_subfunctions" class="code">function CepstralEdit_CreateFcn(hObject, eventdata, handles)</a>
- 0287 <span class="comment">% hObject handle to CepstralEdit (see GCBO)</span>
- 0288 <span class="comment">% eventdata reserved - to be defined in a future version of MATLAB</span>
- 0289 <span class="comment">% handles empty - handles not created until after all CreateFcns called</span>
- 0290
- 0291 <span class="comment">% Hint: edit controls usually have a white background on Windows.</span>
- 0292 <span class="comment">% See ISPC and COMPUTER.</span>
- 0293 <span class="keyword">if</span> ispc
- 0294 set(hObject,<span class="string">'BackgroundColor'</span>,<span class="string">'white'</span>);
- 0295 <span class="keyword">else</span>
- 0296 set(hObject,<span class="string">'BackgroundColor'</span>,get(0,<span class="string">'defaultUicontrolBackgroundColor'</span>));
- 0297 <span class="keyword">end</span>
- 0298
- 0299
- 0300
- 0301 <a name="_sub9" href="#_subfunctions" class="code">function MinClusters_Callback(hObject, eventdata, handles)</a>
- 0302 <span class="comment">% hObject handle to MinClusters (see GCBO)</span>
- 0303 <span class="comment">% eventdata reserved - to be defined in a future version of MATLAB</span>
- 0304 <span class="comment">% handles structure with handles and user data (see GUIDATA)</span>
- 0305
- 0306 <span class="comment">% Hints: get(hObject,'String') returns contents of MinClusters as text</span>
- 0307 <span class="comment">% str2double(get(hObject,'String')) returns contents of MinClusters as a double</span>
- 0308
- 0309
- 0310 <span class="comment">% --- Executes during object creation, after setting all properties.</span>
- 0311 <a name="_sub10" href="#_subfunctions" class="code">function MinClusters_CreateFcn(hObject, eventdata, handles)</a>
- 0312 <span class="comment">% hObject handle to MinClusters (see GCBO)</span>
- 0313 <span class="comment">% eventdata reserved - to be defined in a future version of MATLAB</span>
- 0314 <span class="comment">% handles empty - handles not created until after all CreateFcns called</span>
- 0315
- 0316 <span class="comment">% Hint: edit controls usually have a white background on Windows.</span>
- 0317 <span class="comment">% See ISPC and COMPUTER.</span>
- 0318 <span class="keyword">if</span> ispc
- 0319 set(hObject,<span class="string">'BackgroundColor'</span>,<span class="string">'white'</span>);
- 0320 <span class="keyword">else</span>
- 0321 set(hObject,<span class="string">'BackgroundColor'</span>,get(0,<span class="string">'defaultUicontrolBackgroundColor'</span>));
- 0322 <span class="keyword">end</span>
- 0323
- 0324
- 0325
- 0326 <a name="_sub11" href="#_subfunctions" class="code">function MaxClusters_Callback(hObject, eventdata, handles)</a>
- 0327 <span class="comment">% hObject handle to MaxClusters (see GCBO)</span>
- 0328 <span class="comment">% eventdata reserved - to be defined in a future version of MATLAB</span>
- 0329 <span class="comment">% handles structure with handles and user data (see GUIDATA)</span>
- 0330
- 0331 <span class="comment">% Hints: get(hObject,'String') returns contents of MaxClusters as text</span>
- 0332 <span class="comment">% str2double(get(hObject,'String')) returns contents of MaxClusters as a double</span>
- 0333
- 0334
- 0335 <span class="comment">% --- Executes during object creation, after setting all properties.</span>
- 0336 <a name="_sub12" href="#_subfunctions" class="code">function MaxClusters_CreateFcn(hObject, eventdata, handles)</a>
- 0337 <span class="comment">% hObject handle to MaxClusters (see GCBO)</span>
- 0338 <span class="comment">% eventdata reserved - to be defined in a future version of MATLAB</span>
- 0339 <span class="comment">% handles empty - handles not created until after all CreateFcns called</span>
- 0340
- 0341 <span class="comment">% Hint: edit controls usually have a white background on Windows.</span>
- 0342 <span class="comment">% See ISPC and COMPUTER.</span>
- 0343 <span class="keyword">if</span> ispc
- 0344 set(hObject,<span class="string">'BackgroundColor'</span>,<span class="string">'white'</span>);
- 0345 <span class="keyword">else</span>
- 0346 set(hObject,<span class="string">'BackgroundColor'</span>,get(0,<span class="string">'defaultUicontrolBackgroundColor'</span>));
- 0347 <span class="keyword">end</span>
- 0348
- 0349
- 0350 <span class="comment">% --- Executes on selection change in TransformPopupMenu.</span>
- 0351 <a name="_sub13" href="#_subfunctions" class="code">function TransformPopupMenu_Callback(hObject, eventdata, handles)</a>
- 0352 <span class="comment">% hObject handle to TransformPopupMenu (see GCBO)</span>
- 0353 <span class="comment">% eventdata reserved - to be defined in a future version of MATLAB</span>
- 0354 <span class="comment">% handles structure with handles and user data (see GUIDATA)</span>
- 0355
- 0356 <span class="comment">% Hints: contents = get(hObject,'String') returns TransformPopupMenu contents as cell array</span>
- 0357 <span class="comment">% contents{get(hObject,'Value')} returns selected item from TransformPopupMenu</span>
- 0358
- 0359 <span class="comment">% value = get(hObject,'Value');</span>
- 0360 <span class="comment">%</span>
- 0361 <span class="comment">% if value == 2</span>
- 0362 <span class="comment">% handles.matrix2classify(:,1) = log(handles.matrix2classify(:,1));</span>
- 0363 <span class="comment">% else</span>
- 0364 <span class="comment">% handles.matrix2classify(:,1) = exp(handles.matrix2classify(:,1));</span>
- 0365 <span class="comment">% end</span>
- 0366
- 0367 <span class="comment">% --- Executes during object creation, after setting all properties.</span>
- 0368 <a name="_sub14" href="#_subfunctions" class="code">function TransformPopupMenu_CreateFcn(hObject, eventdata, handles)</a>
- 0369 <span class="comment">% hObject handle to TransformPopupMenu (see GCBO)</span>
- 0370 <span class="comment">% eventdata reserved - to be defined in a future version of MATLAB</span>
- 0371 <span class="comment">% handles empty - handles not created until after all CreateFcns called</span>
- 0372
- 0373 <span class="comment">% Hint: popupmenu controls usually have a white background on Windows.</span>
- 0374 <span class="comment">% See ISPC and COMPUTER.</span>
- 0375 <span class="keyword">if</span> ispc
- 0376 set(hObject,<span class="string">'BackgroundColor'</span>,<span class="string">'white'</span>);
- 0377 <span class="keyword">else</span>
- 0378 set(hObject,<span class="string">'BackgroundColor'</span>,get(0,<span class="string">'defaultUicontrolBackgroundColor'</span>));
- 0379 <span class="keyword">end</span>
- 0380
- 0381 <a name="_sub15" href="#_subfunctions" class="code">function KClasses_Callback(hObject, eventdata, handles)</a>
- 0382 <span class="comment">% hObject handle to KClasses (see GCBO)</span>
- 0383 <span class="comment">% eventdata reserved - to be defined in a future version of MATLAB</span>
- 0384 <span class="comment">% handles structure with handles and user data (see GUIDATA)</span>
- 0385
- 0386 <span class="comment">% Hints: get(hObject,'String') returns contents of KClasses as text</span>
- 0387 <span class="comment">% str2double(get(hObject,'String')) returns contents of KClasses as a double</span>
- 0388
- 0389
- 0390 <span class="comment">% --- Executes during object creation, after setting all properties.</span>
- 0391 <a name="_sub16" href="#_subfunctions" class="code">function KClasses_CreateFcn(hObject, eventdata, handles)</a>
- 0392 <span class="comment">% hObject handle to KClasses (see GCBO)</span>
- 0393 <span class="comment">% eventdata reserved - to be defined in a future version of MATLAB</span>
- 0394 <span class="comment">% handles empty - handles not created until after all CreateFcns called</span>
- 0395
- 0396 <span class="comment">% Hint: edit controls usually have a white background on Windows.</span>
- 0397 <span class="comment">% See ISPC and COMPUTER.</span>
- 0398 <span class="keyword">if</span> ispc
- 0399 set(hObject,<span class="string">'BackgroundColor'</span>,<span class="string">'white'</span>);
- 0400 <span class="keyword">else</span>
- 0401 set(hObject,<span class="string">'BackgroundColor'</span>,get(0,<span class="string">'defaultUicontrolBackgroundColor'</span>));
- 0402 <span class="keyword">end</span>
- 0403
- 0404
- 0405 <span class="comment">% --- Executes on selection change in CepstralPopupMenu.</span>
- 0406 <a name="_sub17" href="#_subfunctions" class="code">function CepstralPopupMenu_Callback(hObject, eventdata, handles)</a>
- 0407 <span class="comment">% hObject handle to CepstralPopupMenu (see GCBO)</span>
- 0408 <span class="comment">% eventdata reserved - to be defined in a future version of MATLAB</span>
- 0409 <span class="comment">% handles structure with handles and user data (see GUIDATA)</span>
- 0410
- 0411 <span class="comment">% Hints: contents = get(hObject,'String') returns CepstralPopupMenu contents as cell array</span>
- 0412 <span class="comment">% contents{get(hObject,'Value')} returns selected item from CepstralPopupMenu</span>
- 0413
- 0414
- 0415 <span class="comment">% --- Executes during object creation, after setting all properties.</span>
- 0416 <a name="_sub18" href="#_subfunctions" class="code">function CepstralPopupMenu_CreateFcn(hObject, eventdata, handles)</a>
- 0417 <span class="comment">% hObject handle to CepstralPopupMenu (see GCBO)</span>
- 0418 <span class="comment">% eventdata reserved - to be defined in a future version of MATLAB</span>
- 0419 <span class="comment">% handles empty - handles not created until after all CreateFcns called</span>
- 0420
- 0421 <span class="comment">% Hint: popupmenu controls usually have a white background on Windows.</span>
- 0422 <span class="comment">% See ISPC and COMPUTER.</span>
- 0423 <span class="keyword">if</span> ispc
- 0424 set(hObject,<span class="string">'BackgroundColor'</span>,<span class="string">'white'</span>);
- 0425 <span class="keyword">else</span>
- 0426 set(hObject,<span class="string">'BackgroundColor'</span>,get(0,<span class="string">'defaultUicontrolBackgroundColor'</span>));
- 0427 <span class="keyword">end</span>
- 0428
- 0429
- 0430
- 0431 <span class="comment">% --- Executes on button press in RangeSpecify.</span>
- 0432 <a name="_sub19" href="#_subfunctions" class="code">function RangeSpecify_Callback(hObject, eventdata, handles)</a>
- 0433 <span class="comment">% hObject handle to RangeSpecify (see GCBO)</span>
- 0434 <span class="comment">% eventdata reserved - to be defined in a future version of MATLAB</span>
- 0435 <span class="comment">% handles structure with handles and user data (see GUIDATA)</span>
- 0436
- 0437 <span class="comment">% Hint: get(hObject,'Value') returns toggle state of RangeSpecify</span>
- 0438
- 0439 state = get(hObject,<span class="string">'Value'</span>);
- 0440
- 0441 <span class="keyword">if</span> state
- 0442 set(handles.KClasses,<span class="string">'Enable'</span>,<span class="string">'off'</span>);
- 0443 set(handles.text3,<span class="string">'Visible'</span>,<span class="string">'on'</span>);
- 0444 set(handles.MinClusters,<span class="string">'Visible'</span>,<span class="string">'on'</span>);
- 0445 set(handles.text4,<span class="string">'Visible'</span>,<span class="string">'on'</span>);
- 0446 set(handles.MaxClusters,<span class="string">'Visible'</span>,<span class="string">'on'</span>);
- 0447 <span class="keyword">else</span>
- 0448 set(handles.KClasses,<span class="string">'Enable'</span>,<span class="string">'on'</span>);
- 0449 set(handles.text3,<span class="string">'Visible'</span>,<span class="string">'off'</span>);
- 0450 set(handles.MinClusters,<span class="string">'Visible'</span>,<span class="string">'off'</span>);
- 0451 set(handles.text4,<span class="string">'Visible'</span>,<span class="string">'off'</span>);
- 0452 set(handles.MaxClusters,<span class="string">'Visible'</span>,<span class="string">'off'</span>);
- 0453 <span class="keyword">end</span>
- 0454
- 0455
- 0456 <span class="comment">% --- Executes on selection change in DistancePopupMenu.</span>
- 0457 <a name="_sub20" href="#_subfunctions" class="code">function DistancePopupMenu_Callback(hObject, eventdata, handles)</a>
- 0458 <span class="comment">% hObject handle to DistancePopupMenu (see GCBO)</span>
- 0459 <span class="comment">% eventdata reserved - to be defined in a future version of MATLAB</span>
- 0460 <span class="comment">% handles structure with handles and user data (see GUIDATA)</span>
- 0461
- 0462 <span class="comment">% Hints: contents = get(hObject,'String') returns DistancePopupMenu contents as cell array</span>
- 0463 <span class="comment">% contents{get(hObject,'Value')} returns selected item from DistancePopupMenu</span>
- 0464
- 0465 contents = get(hObject,<span class="string">'String'</span>);
- 0466
- 0467 dstring = contents{get(hObject,<span class="string">'Value'</span>)};
- 0468
- 0469 <span class="keyword">switch</span> dstring
- 0470 <span class="keyword">case</span> <span class="string">'Squared Euclidean'</span>
- 0471 handles.distancemeasure = <span class="string">'sqEuclidean'</span>
- 0472 <span class="keyword">case</span> <span class="string">'City Block (L1)'</span>
- 0473 handles.distancemeasure = <span class="string">'cityblock'</span>
- 0474 <span class="keyword">case</span> <span class="string">'Cosine'</span>
- 0475 handles.distancemeasure = <span class="string">'cosine'</span>
- 0476 <span class="keyword">case</span> <span class="string">'Correlation'</span>
- 0477 handles.distancemeasure = <span class="string">'correlation'</span>
- 0478 <span class="keyword">end</span>
- 0479
- 0480 guidata(gcbo,handles);
- 0481
- 0482 <span class="comment">% --- Executes during object creation, after setting all properties.</span>
- 0483 <a name="_sub21" href="#_subfunctions" class="code">function DistancePopupMenu_CreateFcn(hObject, eventdata, handles)</a>
- 0484 <span class="comment">% hObject handle to DistancePopupMenu (see GCBO)</span>
- 0485 <span class="comment">% eventdata reserved - to be defined in a future version of MATLAB</span>
- 0486 <span class="comment">% handles empty - handles not created until after all CreateFcns called</span>
- 0487
- 0488 <span class="comment">% Hint: popupmenu controls usually have a white background on Windows.</span>
- 0489 <span class="comment">% See ISPC and COMPUTER.</span>
- 0490 <span class="keyword">if</span> ispc
- 0491 set(hObject,<span class="string">'BackgroundColor'</span>,<span class="string">'white'</span>);
- 0492 <span class="keyword">else</span>
- 0493 set(hObject,<span class="string">'BackgroundColor'</span>,get(0,<span class="string">'defaultUicontrolBackgroundColor'</span>));
- 0494 <span class="keyword">end</span>
- 0495
- 0496 handles.distancemeasure = <span class="string">'sqEuclidean'</span>;
- 0497
- 0498 guidata(gcbo,handles);
- 0499
- 0500 <span class="comment">% --- Executes on button press in DiagnosticCheckbox.</span>
- 0501 <a name="_sub22" href="#_subfunctions" class="code">function DiagnosticCheckbox_Callback(hObject, eventdata, handles)</a>
- 0502 <span class="comment">% hObject handle to DiagnosticCheckbox (see GCBO)</span>
- 0503 <span class="comment">% eventdata reserved - to be defined in a future version of MATLAB</span>
- 0504 <span class="comment">% handles structure with handles and user data (see GUIDATA)</span>
- 0505
- 0506 <span class="comment">% Hint: get(hObject,'Value') returns toggle state of DiagnosticCheckbox</span>
- 0507
- 0508 <a name="_sub23" href="#_subfunctions" class="code">function pcaplot(matrix2classify,classification)</a>
- 0509 <span class="comment">% Plots the first two principal components uses different shapes selected</span>
- 0510 <span class="comment">% randomly and different colors selected randomly to show classes.</span>
- 0511
- 0512 nclusters = length(unique(classification));
- 0513
- 0514 <span class="keyword">if</span> not(isempty(find(classification == 0)))
- 0515 nclusters = nclusters -1;
- 0516 <span class="keyword">end</span>
- 0517
- 0518 colors = rand(nclusters,3);
- 0519 mark = mod(1:nclusters,13)+1;
- 0520
- 0521 [coef, score] = princomp(matrix2classify);
- 0522
- 0523 figure();
- 0524
- 0525 <span class="keyword">for</span> i = 1:length(classification)
- 0526 h = line(score(i,1),score(i,2));
- 0527 markers = set(h,<span class="string">'Marker'</span>);
- 0528 <span class="keyword">if</span> classification(i) == 0 <span class="comment">% For segments which are not classified</span>
- 0529 set(h,<span class="string">'Marker'</span>,markers{4});
- 0530 set(h,<span class="string">'Color'</span>,[0 0 0]);
- 0531 <span class="keyword">else</span>
- 0532 set(h,<span class="string">'Marker'</span>,markers{mark(classification(i))});
- 0533 set(h,<span class="string">'Color'</span>,colors(classification(i),:));
- 0534 <span class="keyword">end</span>
- 0535 <span class="keyword">end</span>
- 0536
- 0537 xlabel(<span class="string">'PCA 1'</span>);
- 0538 ylabel(<span class="string">'PCA 2'</span>);
- 0539
- 0540 <a name="_sub24" href="#_subfunctions" class="code">function classifymatrix = madnormalize(classifymatrix, cols2normalize)</a>
- 0541 <span class="keyword">for</span> i = cols2normalize
- 0542 classifymatrix(:,i) = (classifymatrix(:,i) - median(classifymatrix(:,i))) / mad(classifymatrix(:,i));
- 0543 <span class="keyword">end</span>
- 0544
- 0545
- 0546 <span class="comment">% This code is modified from http://phys.columbia.edu/~aylin/clustering</span>
- 0547
- 0548 <a name="_sub25" href="#_subfunctions" class="code">function c=cluster_aylin(p1,p2);</a>
- 0549 <span class="comment">%enter the p1,p2 found from hneighbors.m and get the struct array c.</span>
- 0550 <span class="comment">%c(i).c will contain the indices of the objects that is in cluster i.</span>
- 0551 <span class="comment">%c(1).c will be the cluster that has the maximum number of objects.</span>
- 0552 nn=size(p1,2);
- 0553 p=std(p1);g=p(p2);p=p';
- 0554 z=zeros(nn,1);zz=zeros(nn,1);
- 0555 n=zeros(1,nn);
- 0556 <span class="keyword">for</span> i=1:nn
- 0557 n(i)=max(max(p1(:,p2(:,i))));
- 0558 <span class="keyword">end</span>
- 0559 gg=[1:nn; max(g); n]';n=find(n<1);
- 0560 [q1,q1]=sort(gg(n,2)');
- 0561 g=gg(n(q1),1);
- 0562 t=cputime;
- 0563 j=1;m=1
- 0564 <span class="keyword">for</span> i=1:length(n)
- 0565 ii=g(i);b=p2(:,ii);a=b;aa=a(find(gg(a,2)<1));
- 0566 <span class="keyword">if</span> length([0; unique(z(aa))])<=2;a1=1;a2=0;
- 0567 <span class="keyword">while</span> a1~=a2;a1=length(aa);
- 0568 a=unique(p2(:,a));a=a(find(gg(a,2)<1));
- 0569 a=unique(a(find(gg(a,2)<=mean(gg(aa,2))+std(gg(aa,2)))));
- 0570 a=a(find(ismember(a,aa)==0));
- 0571 <span class="keyword">if</span> ~isempty(a);aa=[aa;a];
- 0572 jj=aa(find(z(aa)));
- 0573 <span class="keyword">if</span> ~isempty(jj);;
- 0574 u=unique(z(jj));
- 0575 <span class="keyword">if</span> length(u)==1;
- 0576 zz(aa(find(~z(aa))))=m;z(aa)=u;m=m+1;
- 0577 <span class="keyword">end</span>
- 0578 <span class="keyword">break</span>;
- 0579 <span class="keyword">end</span>
- 0580 <span class="keyword">end</span>;a2=length(aa);
- 0581 <span class="keyword">end</span>;a=aa;
- 0582 jj=a(find(z(a)));
- 0583 <span class="keyword">if</span> isempty(jj);
- 0584 z(a)=j;j=j+1;
- 0585 zz(a)=m;zz(b)=m-.1;zz(ii)=m-.2;m=m+1;
- 0586 <span class="keyword">end</span>
- 0587 <span class="keyword">end</span>
- 0588 <span class="keyword">end</span>
- 0589 u=unique(z)
- 0590 u=u(find(u));v=length(u);vv=floor(1/v);<span class="keyword">if</span> vv;vv=<span class="string">' is'</span>;<span class="keyword">else</span> vv=<span class="string">'s are'</span>;<span class="keyword">end</span>
- 0591 fprintf([int2str(v) <span class="string">' cluster'</span> vv <span class="string">' found in '</span> num2str(cputime-t) <span class="string">'sec\n\n'</span>])
- 0592 q0=[];<span class="keyword">for</span> i=1:v;qq=find(z==u(i));q0=[q0 length(qq)];<span class="keyword">end</span>;
- 0593 [q1,q2]=sort(q0);<span class="comment">%q2=q2(find(100*q1/nn>1));v=length(q2);</span>
- 0594 c=[];<span class="keyword">for</span> i=1:v;qq=find(z==u(q2(i)));[j,j]=sort(zz(qq));c(v-i+1).c=qq(j);<span class="keyword">end</span>;
- 0595 <span class="keyword">if</span> isempty(c);fprintf(<span class="string">'\tNo cluster was found. \n \tscale the data (step size must be 1)\n'</span>);<span class="keyword">end</span>
- 0596
- 0597
- 0598 <a name="_sub26" href="#_subfunctions" class="code">function [p1,p2]=hneighbors(e);</a>
- 0599 <span class="comment">% this function finds the neighbors of each object in 'e' within a unit hypercube</span>
- 0600 <span class="comment">% and returns the sorted object distances to q.q1 and their identities to q.q2 , 'e' is a</span>
- 0601 <span class="comment">% matrix where i th row and j th column represents the j th component of the i th object.</span>
- 0602 s=<span class="string">'find('</span>;i=<span class="string">'abs(e(:,%d)-e(i,%d))<1&'</span>;
- 0603 <span class="comment">% assuming that the data is given scaled and the characteristic step size is 1, variable s</span>
- 0604 <span class="comment">% keeps a script to find the objects that lie within a unit hypercube around the i th object.</span>
- 0605 <span class="keyword">for</span> j=1:size(e,2);
- 0606 s=[s sprintf(i,j,j)];
- 0607 <span class="keyword">end</span>;s([end end+1])=<span class="string">');'</span>;
- 0608 <span class="comment">% runs the script s for each of the objects and stores the sorted distances</span>
- 0609 <span class="comment">% from the i th object in q(i).q1 and their indentities in q(i).q2</span>
- 0610 nn=size(e,1);m=ceil(nn^(1/4));p1=ones(m,nn);p2=kron(ones(m,1),1:nn);
- 0611 <span class="keyword">for</span> i=1:nn;
- 0612 j=eval(s);
- 0613 [q,qq]=sort(sqrt(sum((e(j,:)-kron(ones(length(j),1),e(i,:)))'.^2)));q=q(find(q<1));mm=length(q);
- 0614 qq=j(qq(1:mm))';mn=min([m mm]);
- 0615 p1(1:mn,i)=q(1:mn)';
- 0616 p2(1:mn,i)=qq(1:mn)';
- 0617 <span class="keyword">end</span>
- 0618
- 0619
- 0620 <a name="_sub27" href="#_subfunctions" class="code">function classification = cluster_hierarchical(matrix2classify)</a>
- 0621 [p1,p2] = <a href="#_sub26" class="code" title="subfunction [p1,p2]=hneighbors(e);">hneighbors</a>(matrix2classify);
- 0622 c = <a href="#_sub25" class="code" title="subfunction c=cluster_aylin(p1,p2);">cluster_aylin</a>(p1,p2);
- 0623
- 0624 nclusters = size(c,2);
- 0625
- 0626 total_classified = 0
- 0627
- 0628 nsegments = size(matrix2classify,1);
- 0629
- 0630 classification = zeros(nsegments,1);
- 0631
- 0632 <span class="keyword">for</span> i = 1:nclusters
- 0633 <span class="keyword">for</span> j = 1:length(c(i).c)
- 0634 classification(c(i).c(j)) = i;
- 0635 <span class="keyword">end</span>
- 0636 <span class="keyword">end</span>
- 0637 ;
- 0638
- 0639
- 0640 <span class="comment">% --- Executes on button press in HierarchicalRadioButton.</span>
- 0641 <a name="_sub28" href="#_subfunctions" class="code">function HierarchicalRadioButton_Callback(hObject, eventdata, handles)</a>
- 0642 <span class="comment">% hObject handle to HierarchicalRadioButton (see GCBO)</span>
- 0643 <span class="comment">% eventdata reserved - to be defined in a future version of MATLAB</span>
- 0644 <span class="comment">% handles structure with handles and user data (see GUIDATA)</span>
- 0645
- 0646 <span class="comment">% Hint: get(hObject,'Value') returns toggle state of HierarchicalRadioButton</span>
- 0647
- 0648 selected = get(hObject,<span class="string">'Value'</span>);
- 0649
- 0650 <span class="keyword">if</span> selected
- 0651 handles.cluster_method = <span class="string">'hierarchical'</span>;
- 0652 <span class="keyword">end</span>
- 0653
- 0654 guidata(gcbo,handles);
- 0655
- 0656
- 0657 <span class="comment">% --- Executes on button press in KmeansRadioButton.</span>
- 0658 <a name="_sub29" href="#_subfunctions" class="code">function KmeansRadioButton_Callback(hObject, eventdata, handles)</a>
- 0659 <span class="comment">% hObject handle to KmeansRadioButton (see GCBO)</span>
- 0660 <span class="comment">% eventdata reserved - to be defined in a future version of MATLAB</span>
- 0661 <span class="comment">% handles structure with handles and user data (see GUIDATA)</span>
- 0662
- 0663 <span class="comment">% Hint: get(hObject,'Value') returns toggle state of KmeansRadioButton</span>
- 0664
- 0665 selected = get(hObject,<span class="string">'Value'</span>);
- 0666
- 0667 <span class="keyword">if</span> selected
- 0668 handles.cluster_method = <span class="string">'kmeans'</span>;
- 0669 <span class="keyword">end</span>
- 0670
- 0671 guidata(gcbo,handles);
- 0672
- 0673
- 0674
- 0675
- 0676 <a name="_sub30" href="#_subfunctions" class="code">function SegLenWeight_Callback(hObject, eventdata, handles)</a>
- 0677 <span class="comment">% hObject handle to SegLenWeight (see GCBO)</span>
- 0678 <span class="comment">% eventdata reserved - to be defined in a future version of MATLAB</span>
- 0679 <span class="comment">% handles structure with handles and user data (see GUIDATA)</span>
- 0680
- 0681 <span class="comment">% Hints: get(hObject,'String') returns contents of SegLenWeight as text</span>
- 0682 <span class="comment">% str2double(get(hObject,'String')) returns contents of SegLenWeight as a double</span>
- 0683
- 0684
- 0685 <span class="comment">% --- Executes during object creation, after setting all properties.</span>
- 0686 <a name="_sub31" href="#_subfunctions" class="code">function SegLenWeight_CreateFcn(hObject, eventdata, handles)</a>
- 0687 <span class="comment">% hObject handle to SegLenWeight (see GCBO)</span>
- 0688 <span class="comment">% eventdata reserved - to be defined in a future version of MATLAB</span>
- 0689 <span class="comment">% handles empty - handles not created until after all CreateFcns called</span>
- 0690
- 0691 <span class="comment">% Hint: edit controls usually have a white background on Windows.</span>
- 0692 <span class="comment">% See ISPC and COMPUTER.</span>
- 0693 <span class="keyword">if</span> ispc
- 0694 set(hObject,<span class="string">'BackgroundColor'</span>,<span class="string">'white'</span>);
- 0695 <span class="keyword">else</span>
- 0696 set(hObject,<span class="string">'BackgroundColor'</span>,get(0,<span class="string">'defaultUicontrolBackgroundColor'</span>));
- 0697 <span class="keyword">end</span>
- 0698
- 0699</pre></div>
- <hr><address>Generated on Fri 12-Aug-2011 11:36:15 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> © 2005</address>
- </body>
- </html>
|