KDE1DGUI GUI to Kernel Density Estimator. CALL: kdegui; Example data = wraylrnd(1,100,1); kde1dgui See also kde2dgui, kde
Kernel Density Estimator. | |
Create or alter KDE OPTIONS structure. | |
Multivariate Kernel Function. | |
Plot contents of pdf structures | |
Random sampling of points from a data-set | |
Plots a histogram | |
Delete file or graphics object. | |
Convert to double precision. | |
Error dialog box. | |
Evaluate expression in workspace. | |
Create figure window. | |
Get handle to current callback figure. | |
Get object properties. | |
Get value of application-defined data. | |
A function to handle default GUIDE GUI creation and callback dispatch. | |
Store or retrieve application data. | |
Help dialog box. | |
Hold current graph. | |
Convert integer to string (Fast version). | |
True for character array (string). | |
True if arrays are numerically equal. | |
Return hold state. | |
True for the PC (Windows) version of MATLAB. | |
Linearly spaced vector. | |
Convert string to lowercase. | |
Name of currently executing M-file. | |
Message box. | |
Convert number to string. (Fast version) | |
Linear plot. | |
Set object properties. | |
Set application-defined data. | |
Write formatted data to string. | |
Convert string to double precision value. | |
Construct a function_handle from a function name string. | |
Compare strings. | |
Find possible matches for string. | |
Create or convert to structure array. | |
Resume execution of blocked M-file. | |
Block execution and wait for resume. |
0001 function varargout = kde1dgui(varargin) 0002 %KDE1DGUI GUI to Kernel Density Estimator. 0003 % 0004 % CALL: kdegui; 0005 % 0006 % Example 0007 % data = wraylrnd(1,100,1); 0008 % kde1dgui 0009 % 0010 % See also kde2dgui, kde 0011 0012 0013 % Tested on matlab7 0014 % By pab Jan2005 0015 % revised pab sept 2005 0016 % - fixed some bugs + updated help header 0017 0018 % Edit the above text to modify the response to help kde1dgui 0019 0020 % Last Modified by GUIDE v2.5 19-Apr-2005 00:01:13 0021 0022 % Begin initialization code - DO NOT EDIT 0023 gui_Singleton = 0; 0024 gui_State = struct('gui_Name', mfilename, ... 0025 'gui_Singleton', gui_Singleton, ... 0026 'gui_OpeningFcn', @kde1dgui_OpeningFcn, ... 0027 'gui_OutputFcn', @kde1dgui_OutputFcn, ... 0028 'gui_LayoutFcn', [], ... 0029 'gui_Callback', []); 0030 if nargin && ischar(varargin{1}) 0031 gui_State.gui_Callback = str2func(varargin{1}); 0032 end 0033 0034 if nargout 0035 [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); 0036 else 0037 gui_mainfcn(gui_State, varargin{:}); 0038 end 0039 % End initialization code - DO NOT EDIT 0040 0041 0042 % --- Executes just before kde1dgui is made visible. 0043 function kde1dgui_OpeningFcn(hObject, eventdata, handles, varargin) 0044 % This function has no output args, see OutputFcn. 0045 % hObject handle to figure 0046 % eventdata reserved - to be defined in a future version of MATLAB 0047 % handles structure with handles and user data (see GUIDATA) 0048 % varargin unrecognized PropertyName/PropertyValue pairs from the 0049 % command line (see VARARGIN) 0050 0051 % Choose default command line output for kde1dgui 0052 handles.output = hObject; 0053 0054 0055 handles.histPanel.bins = 10; 0056 0057 %handles.dataSelected = []; 0058 0059 0060 kdeopts = kdeoptset('kde'); 0061 kdeopts.fixh = 1; 0062 kdeopts.adaptive = 0; 0063 kdeopts.transform = 0; 0064 kdeopts.addbumps = 0; 0065 kdeopts.bumpLinestyle = 'r--'; 0066 kdeopts.linestyle = 'k-'; 0067 0068 %handles.kdePanel.kdeopts = kdeopts; 0069 0070 kdePanel.kdeopts = kdeopts; 0071 0072 setappdata(handles.figure1,'kdePanel',kdePanel) 0073 % Populate kdePanel 0074 updateKdePanel(handles); 0075 0076 setappdata(handles.figure1,'dataSelected',[]) 0077 0078 % Populate the data menu 0079 updateDataMenu(handles) 0080 set(handles.dataMenu,'Value',1) 0081 %Resample panel 0082 set(handles.rbNo,'Value',1) 0083 0084 0085 % Update handles structure 0086 guidata(hObject, handles); 0087 0088 0089 % UIWAIT makes kde1dgui wait for user response (see UIRESUME) 0090 % uiwait(handles.figure1); 0091 0092 function updateKdePanel(handles) 0093 %UPDATEKDEPANEL Updates KDEPANEL of gui with current settings in kdePanel struct 0094 0095 0096 kdePanel = getappdata(handles.figure1,'kdePanel'); 0097 opts = kdePanel.kdeopts; 0098 0099 %opts = handles.kdePanel.kdeopts; 0100 0101 0102 if opts.adaptive==1 | opts.transform==1 0103 opts.addbumps=0; 0104 kdePanel.kdeopts.addbumps=0; 0105 set(handles.cbAddBumps,'Enable','off') 0106 set(handles.eBumpLinestyle,'Enable','off') 0107 % Update kdePanel structure 0108 setappdata(handles.figure1,'kdePanel',kdePanel); 0109 % Update handles structure 0110 %guidata(hObject, handles); 0111 else 0112 set(handles.eBumpLinestyle,'Enable','on') 0113 set(handles.cbAddBumps,'Enable','on') 0114 end 0115 if kdePanel.kdeopts.addbumps ==1 0116 set(handles.eBumpLinestyle,'Visible','on') 0117 else 0118 set(handles.eBumpLinestyle,'Visible','off') 0119 end 0120 if opts.fixh==1 0121 set(handles.eHs,'Enable','off') 0122 set(handles.hruleMenu,'Enable','on') 0123 else 0124 set(handles.hruleMenu,'Enable','off') 0125 set(handles.eHs,'Enable','on') 0126 end 0127 0128 set(handles.eHs,'String',num2str(opts.hs)) 0129 set(handles.eL2,'String',num2str(opts.L2)) 0130 set(handles.eAlpha,'String',num2str(opts.alpha)) 0131 set(handles.cbHRule, 'Value',opts.fixh); 0132 set(handles.cbAdaptive, 'Value',opts.adaptive); 0133 set(handles.cbTransform, 'Value',opts.transform) 0134 set(handles.cbAddBumps, 'Value',opts.addbumps) 0135 set(handles.eBumpLinestyle,'String',opts.bumpLinestyle) 0136 set(handles.eLinestyle,'String',opts.linestyle) 0137 0138 kernelEntries = lower(get(handles.kernelMenu,'String')); 0139 ix = strmatch(lower(opts.kernel),kernelEntries); 0140 if length(ix) == 1 0141 set(handles.kernelMenu,'Value',ix); 0142 end 0143 hruleEntries = get(handles.hruleMenu,'String'); 0144 ix = strmatch(opts.hsMethod,hruleEntries); 0145 if length(ix) == 1 0146 set(handles.hruleMenu,'Value',ix); 0147 end 0148 0149 0150 % --- Outputs from this function are returned to the command line. 0151 function varargout = kde1dgui_OutputFcn(hObject, eventdata, handles) 0152 % varargout cell array for returning output args (see VARARGOUT); 0153 % hObject handle to figure 0154 % eventdata reserved - to be defined in a future version of MATLAB 0155 % handles structure with handles and user data (see GUIDATA) 0156 0157 % Get default command line output from handles structure 0158 varargout{1} = handles.output; 0159 0160 0161 % --- Executes when user attempts to close figure1. 0162 function figure1_CloseRequestFcn(hObject, eventdata, handles) 0163 % hObject handle to figure1 (see GCBO) 0164 % eventdata reserved - to be defined in a future version of MATLAB 0165 % handles structure with handles and user data (see GUIDATA) 0166 0167 % Hint: delete(hObject) closes the figure 0168 delete(hObject); 0169 0170 0171 % --- Executes on selection change in hruleMenu. 0172 function hruleMenu_Callback(hObject, eventdata, handles) 0173 % hObject handle to hruleMenu (see GCBO) 0174 % eventdata reserved - to be defined in a future version of MATLAB 0175 % handles structure with handles and user data (see GUIDATA) 0176 0177 % Hints: contents = get(hObject,'String') returns hruleMenu contents as cell array 0178 % contents{get(hObject,'Value')} returns selected item from hruleMenu 0179 0180 %if get(handles.cbHRule,'Value')==0 0181 val = get(hObject,'Value'); 0182 strList = get(hObject,'String'); 0183 kdePanel = getappdata(handles.figure1,'kdePanel'); 0184 kdePanel.kdeopts.hsMethod = strList{val}; 0185 setappdata(handles.figure1,'kdePanel',kdePanel); 0186 %end 0187 0188 0189 % --- Executes during object creation, after setting all properties. 0190 function hruleMenu_CreateFcn(hObject, eventdata, handles) 0191 % hObject handle to hruleMenu (see GCBO) 0192 % eventdata reserved - to be defined in a future version of MATLAB 0193 % handles empty - handles not created until after all CreateFcns called 0194 0195 % Hint: popupmenu controls usually have a white background on Windows. 0196 % See ISPC and COMPUTER. 0197 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 0198 set(hObject,'BackgroundColor','white'); 0199 end 0200 0201 0202 0203 function eHs_Callback(hObject, eventdata, handles) 0204 % hObject handle to eHs (see GCBO) 0205 % eventdata reserved - to be defined in a future version of MATLAB 0206 % handles structure with handles and user data (see GUIDATA) 0207 0208 % Hints: get(hObject,'String') returns contents of eHs as text 0209 % str2double(get(hObject,'String')) returns contents of eHs as a double 0210 0211 hs = str2double(get(hObject,'String')); 0212 0213 if (isnan(hs)) 0214 hs = []; 0215 end 0216 kdePanel = getappdata(handles.figure1,'kdePanel'); 0217 kdePanel.kdeopts.hs = hs; 0218 setappdata(handles.figure1,'kdePanel',kdePanel); 0219 0220 0221 0222 0223 % --- Executes during object creation, after setting all properties. 0224 function eHs_CreateFcn(hObject, eventdata, handles) 0225 % hObject handle to eHs (see GCBO) 0226 % eventdata reserved - to be defined in a future version of MATLAB 0227 % handles empty - handles not created until after all CreateFcns called 0228 0229 % Hint: edit controls usually have a white background on Windows. 0230 % See ISPC and COMPUTER. 0231 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 0232 set(hObject,'BackgroundColor','white'); 0233 end 0234 0235 0236 0237 function eL2_Callback(hObject, eventdata, handles) 0238 % hObject handle to eL2 (see GCBO) 0239 % eventdata reserved - to be defined in a future version of MATLAB 0240 % handles structure with handles and user data (see GUIDATA) 0241 0242 % Hints: get(hObject,'String') returns contents of eL2 as text 0243 % str2double(get(hObject,'String')) returns contents of eL2 as a double 0244 L2 = str2double(get(hObject,'String')); 0245 invalidInput = isnan(L2)| (L2 <0); 0246 if (invalidInput) 0247 L2 = 1; 0248 end 0249 nonLinear = (L2~=1); 0250 kdePanel = getappdata(handles.figure1,'kdePanel'); 0251 0252 kdePanel.kdeopts.transform=nonLinear; 0253 kdePanel.kdeopts.L2 = L2; 0254 0255 setappdata(handles.figure1,'kdePanel',kdePanel) 0256 0257 0258 updateKdePanel(handles) 0259 0260 0261 0262 % --- Executes during object creation, after setting all properties. 0263 function eL2_CreateFcn(hObject, eventdata, handles) 0264 % hObject handle to eL2 (see GCBO) 0265 % eventdata reserved - to be defined in a future version of MATLAB 0266 % handles empty - handles not created until after all CreateFcns called 0267 0268 % Hint: edit controls usually have a white background on Windows. 0269 % See ISPC and COMPUTER. 0270 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 0271 set(hObject,'BackgroundColor','white'); 0272 end 0273 0274 0275 % --- Executes on button press in cbAdaptive. 0276 function cbAdaptive_Callback(hObject, eventdata, handles) 0277 % hObject handle to cbAdaptive (see GCBO) 0278 % eventdata reserved - to be defined in a future version of MATLAB 0279 % handles structure with handles and user data (see GUIDATA) 0280 0281 % Hint: get(hObject,'Value') returns toggle state of cbAdaptive 0282 0283 val = get(hObject,'Value'); 0284 if val==1 0285 alpha1 = 0.5; 0286 else 0287 alpha1=0; 0288 end 0289 adaptive = (alpha1~=0); 0290 kdePanel = getappdata(handles.figure1,'kdePanel'); 0291 kdePanel.kdeopts.adaptive=adaptive; 0292 kdePanel.kdeopts.alpha = alpha1; 0293 0294 setappdata(handles.figure1,'kdePanel',kdePanel) 0295 updateKdePanel(handles) 0296 0297 0298 0299 function eAlpha_Callback(hObject, eventdata, handles) 0300 % hObject handle to eAlpha (see GCBO) 0301 % eventdata reserved - to be defined in a future version of MATLAB 0302 % handles structure with handles and user data (see GUIDATA) 0303 0304 % Hints: get(hObject,'String') returns contents of eAlpha as text 0305 % str2double(get(hObject,'String')) returns contents of eAlpha as a double 0306 0307 alpha1 = str2double(get(hObject,'String')); 0308 invalidInput = isnan(alpha1) | (alpha1<0) | (1<alpha1); 0309 if (invalidInput) 0310 alpha1 = 0; 0311 end 0312 adaptive = (alpha1~=0); 0313 kdePanel = getappdata(handles.figure1,'kdePanel'); 0314 kdePanel.kdeopts.adaptive=adaptive; 0315 kdePanel.kdeopts.alpha = alpha1; 0316 0317 setappdata(handles.figure1,'kdePanel',kdePanel); 0318 updateKdePanel(handles) 0319 0320 0321 % --- Executes during object creation, after setting all properties. 0322 function eAlpha_CreateFcn(hObject, eventdata, handles) 0323 % hObject handle to eAlpha (see GCBO) 0324 % eventdata reserved - to be defined in a future version of MATLAB 0325 % handles empty - handles not created until after all CreateFcns called 0326 0327 % Hint: edit controls usually have a white background on Windows. 0328 % See ISPC and COMPUTER. 0329 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 0330 set(hObject,'BackgroundColor','white'); 0331 end 0332 0333 0334 % --- Executes on button press in cbTransform. 0335 function cbTransform_Callback(hObject, eventdata, handles) 0336 % hObject handle to cbTransform (see GCBO) 0337 % eventdata reserved - to be defined in a future version of MATLAB 0338 % handles structure with handles and user data (see GUIDATA) 0339 0340 % Hint: get(hObject,'Value') returns toggle state of cbTransform 0341 0342 0343 val = get(hObject,'Value'); 0344 if val==1 0345 data = getappdata(handles.figure1,'dataSelected'); 0346 if any(data<0) 0347 set(hObject,'Value',0); 0348 errordlg('Make sure data>0 for this option!','Error transform','modal') 0349 return 0350 end 0351 L2 = 0.5; 0352 else 0353 L2=1; 0354 end 0355 nonLinear = (L2~=1); 0356 0357 kdePanel = getappdata(handles.figure1,'kdePanel'); 0358 kdePanel.kdeopts.transform=nonLinear; 0359 kdePanel.kdeopts.L2 = L2; 0360 setappdata(handles.figure1,'kdePanel',kdePanel) 0361 0362 updateKdePanel(handles) 0363 0364 0365 0366 % --- Executes on button press in cbHRule. 0367 function cbHRule_Callback(hObject, eventdata, handles) 0368 % hObject handle to cbHRule (see GCBO) 0369 % eventdata reserved - to be defined in a future version of MATLAB 0370 % handles structure with handles and user data (see GUIDATA) 0371 0372 % Hint: get(hObject,'Value') returns toggle state of cbHRule 0373 0374 fixh = get(hObject,'Value'); 0375 0376 if fixh==1 0377 set(handles.hruleMenu,'Enable','on') 0378 set(handles.eHs,'Enable','off') 0379 else 0380 set(handles.hruleMenu,'Enable','off') 0381 set(handles.eHs,'Enable','on') 0382 end 0383 kdePanel = getappdata(handles.figure1,'kdePanel'); 0384 0385 kdePanel.kdeopts.fixh=fixh; 0386 setappdata(handles.figure1,'kdePanel',kdePanel); 0387 0388 0389 % --- Executes on button press in cbAddBumps. 0390 function cbAddBumps_Callback(hObject, eventdata, handles) 0391 % hObject handle to cbAddBumps (see GCBO) 0392 % eventdata reserved - to be defined in a future version of MATLAB 0393 % handles structure with handles and user data (see GUIDATA) 0394 0395 % Hint: get(hObject,'Value') returns toggle state of cbAddBumps 0396 0397 kdePanel = getappdata(handles.figure1,'kdePanel'); 0398 kdePanel.kdeopts.addbumps=get(hObject,'Value'); 0399 if kdePanel.kdeopts.addbumps ==1 0400 set(handles.eBumpLinestyle,'Visible','on') 0401 else 0402 set(handles.eBumpLinestyle,'Visible','off') 0403 end 0404 setappdata(handles.figure1,'kdePanel',kdePanel); 0405 %updateKdePanel(handles) 0406 0407 % --- Executes on selection change in kernelMenu. 0408 function kernelMenu_Callback(hObject, eventdata, handles) 0409 % hObject handle to kernelMenu (see GCBO) 0410 % eventdata reserved - to be defined in a future version of MATLAB 0411 % handles structure with handles and user data (see GUIDATA) 0412 0413 % Hints: contents = get(hObject,'String') returns kernelMenu contents as cell array 0414 % contents{get(hObject,'Value')} returns selected item from kernelMenu 0415 0416 val = get(hObject,'Value'); 0417 strList = get(hObject,'String'); 0418 0419 kdePanel = getappdata(handles.figure1,'kdePanel'); 0420 kdePanel.kdeopts.kernel = strList{val}; 0421 setappdata(handles.figure1,'kdePanel',kdePanel); 0422 0423 % --- Executes during object creation, after setting all properties. 0424 function kernelMenu_CreateFcn(hObject, eventdata, handles) 0425 % hObject handle to kernelMenu (see GCBO) 0426 % eventdata reserved - to be defined in a future version of MATLAB 0427 % handles empty - handles not created until after all CreateFcns called 0428 0429 % Hint: popupmenu controls usually have a white background on Windows. 0430 % See ISPC and COMPUTER. 0431 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 0432 set(hObject,'BackgroundColor','white'); 0433 end 0434 0435 0436 0437 function eNumBins_Callback(hObject, eventdata, handles) 0438 % hObject handle to eNumBins (see GCBO) 0439 % eventdata reserved - to be defined in a future version of MATLAB 0440 % handles structure with handles and user data (see GUIDATA) 0441 0442 % Hints: get(hObject,'String') returns contents of eNumBins as text 0443 % str2double(get(hObject,'String')) returns contents of eNumBins as a double 0444 0445 bins = str2double(get(hObject,'String')); 0446 invalidInput = isnan(bins) | (bins<1); 0447 if (invalidInput) 0448 bins = 10; 0449 set(hObject,'String',int2str(bins)) 0450 end 0451 0452 handles.histPanel.bins=bins; 0453 0454 guidata(hObject,handles) 0455 0456 0457 0458 % --- Executes during object creation, after setting all properties. 0459 function eNumBins_CreateFcn(hObject, eventdata, handles) 0460 % hObject handle to eNumBins (see GCBO) 0461 % eventdata reserved - to be defined in a future version of MATLAB 0462 % handles empty - handles not created until after all CreateFcns called 0463 0464 % Hint: edit controls usually have a white background on Windows. 0465 % See ISPC and COMPUTER. 0466 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 0467 set(hObject,'BackgroundColor','white'); 0468 end 0469 0470 0471 0472 0473 function eSampleSize_Callback(hObject, eventdata, handles) 0474 % hObject handle to eSampleSize (see GCBO) 0475 % eventdata reserved - to be defined in a future version of MATLAB 0476 % handles structure with handles and user data (see GUIDATA) 0477 0478 % Hints: get(hObject,'String') returns contents of eSampleSize as text 0479 % str2double(get(hObject,'String')) returns contents of eSampleSize as a double 0480 0481 0482 % --- Executes during object creation, after setting all properties. 0483 function eSampleSize_CreateFcn(hObject, eventdata, handles) 0484 % hObject handle to eSampleSize (see GCBO) 0485 % eventdata reserved - to be defined in a future version of MATLAB 0486 % handles empty - handles not created until after all CreateFcns called 0487 0488 % Hint: edit controls usually have a white background on Windows. 0489 % See ISPC and COMPUTER. 0490 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 0491 set(hObject,'BackgroundColor','white'); 0492 end 0493 0494 0495 0496 0497 0498 function updateDataMenu(handles) 0499 %UPDATEDATAMENU 0500 0501 % Updates the listbox to match the current workspace 0502 vars = evalin('base','who'); 0503 0504 for ix =length(vars):-1:1 0505 NsizeVar1 = sprintf('size(%s)',vars{ix}); 0506 Nsize = evalin('base',NsizeVar1,'errordlg(lasterr,''Error generating plots'',''modal'')'); 0507 isnumericVar1 = sprintf('isnumeric(%s)',vars{ix}); 0508 isNumber = evalin('base',isnumericVar1,'errordlg(lasterr,''Error generating plots'',''modal'')'); 0509 if prod(Nsize)~= max(Nsize) | ~isNumber 0510 % remove data if dimension>1 or if not numeric data 0511 vars(ix) = []; 0512 end 0513 end 0514 0515 if ~isempty(vars) 0516 set(handles.dataMenu,'String',vars) 0517 end 0518 % --- Executes on button press in tbHold. 0519 function tbHold_Callback(hObject, eventdata, handles) 0520 % hObject handle to tbHold (see GCBO) 0521 % eventdata reserved - to be defined in a future version of MATLAB 0522 % handles structure with handles and user data (see GUIDATA) 0523 0524 % Hint: get(hObject,'Value') returns toggle state of tbHold 0525 0526 kdePanel = getappdata(handles.figure1,'kdePanel'); 0527 buttonState = get(hObject,'Value') ; 0528 if buttonState == get(hObject,'Max') 0529 0530 ls = findNextLinestyle(kdePanel.kdeopts.linestyle); 0531 set(handles.tbHold,'String', 'Hold On'); 0532 hold(handles.kdeAxes,'on') 0533 0534 elseif buttonState== get(hObject,'Min') 0535 0536 ls = 'k-'; 0537 set(handles.tbHold,'String', 'Hold Off'); 0538 hold(handles.kdeAxes,'off') 0539 end 0540 set(handles.eLinestyle,'string',ls) 0541 kdePanel.kdeopts.linestyle = ls; 0542 setappdata(handles.figure1,'kdePanel',kdePanel); 0543 0544 0545 0546 % --- Executes on button press in pbClose. 0547 function pbClose_Callback(hObject, eventdata, handles) 0548 % hObject handle to pbClose (see GCBO) 0549 % eventdata reserved - to be defined in a future version of MATLAB 0550 % handles structure with handles and user data (see GUIDATA) 0551 0552 delete(gcbf) 0553 0554 0555 % --- Executes on button press in pbPlotKde. 0556 function pbPlotKde_Callback(hObject, eventdata, handles) 0557 % hObject handle to pbPlotKde (see GCBO) 0558 % eventdata reserved - to be defined in a future version of MATLAB 0559 % handles structure with handles and user data (see GUIDATA) 0560 0561 %data = evalin('base',handles.lbDataSelected,'errordlg(lasterr,''Error generating plots'',''modal'')'); 0562 0563 data = getappdata(handles.figure1,'dataSelected'); 0564 0565 if isempty(data) 0566 uiwait(msgbox('Load data before plotting!','No data loaded','modal')); 0567 return 0568 end 0569 0570 kdePanel = getappdata(handles.figure1,'kdePanel'); 0571 if kdePanel.kdeopts.fixh==1 0572 kdePanel.kdeopts.hs = 0; 0573 end 0574 0575 figure(handles.figure1) 0576 0577 0578 0579 pdf = kde(data,kdePanel.kdeopts); 0580 0581 pdf.title = sprintf('h = %s',num2str(pdf.options.hs)); 0582 %axis(handles.kdeAxes); 0583 ls = kdePanel.kdeopts.linestyle; 0584 if isempty(ls) 0585 pdfplot(pdf) 0586 %H=plot(pdf.x{1},pdf.f); 0587 else 0588 pdfplot(pdf,ls) 0589 %H=plot(pdf.x{1},pdf.f,ls); 0590 end 0591 0592 if ((kdePanel.kdeopts.addbumps==1) & ... 0593 (kdePanel.kdeopts.adaptive==0) & ... 0594 (kdePanel.kdeopts.transform==0)) 0595 hs = pdf.options.hs; 0596 n = length(data); 0597 x0 = linspace(-2,2); 0598 y = mkernel(x0,pdf.options.kernel)/(n*hs); 0599 hold_state = ishold; 0600 hold on 0601 linestyle = kdePanel.kdeopts.bumpLinestyle; 0602 for i=1:n 0603 plot(data(i)+x0*hs,y,linestyle); 0604 plot(repmat(data(i),1,2), [0 max(y)],linestyle) 0605 end 0606 if ~hold_state, 0607 hold off, 0608 end 0609 end 0610 0611 %pdfplot(pdf,ls) 0612 hs = kdePanel.kdeopts.hs; 0613 if ( isempty(hs) | hs<=0) 0614 kdePanel.kdeopts.hs=pdf.options.hs; 0615 setappdata(handles.figure1,'kdePanel',kdePanel) 0616 updateKdePanel(handles) 0617 end 0618 0619 if ishold 0620 ls = kdePanel.kdeopts.linestyle; 0621 nextLs = findNextLinestyle(ls); 0622 kdePanel.kdeopts.linestyle = nextLs; 0623 set(handles.eLinestyle,'String',nextLs) 0624 setappdata(handles.figure1,'kdePanel',kdePanel); 0625 end 0626 0627 function nextLs = findNextLinestyle(ls) 0628 defaultColorOrder = 'kbrgmcy'; 0629 defaultLinestyleOrder = {'-','--','-.',':',':.',':o',':x',':+',':*',':s'}; 0630 nextColorIdx = 1; 0631 nextLsIdx = 1; 0632 if ~isempty(ls) 0633 Nc = length(defaultColorOrder); % Number of valid colors 0634 Nls = length(defaultLinestyleOrder); 0635 startIndex = double('a'); 0636 endIndex = double('z'); 0637 shiftIndex = startIndex-1; 0638 lettersHandled = endIndex-shiftIndex; 0639 0640 ind1 = double(defaultColorOrder)- shiftIndex; 0641 ind2 = repmat(Nc+1,lettersHandled,1); 0642 ind2(ind1) = 1:Nc; 0643 0644 ind3 = double(ls)-shiftIndex; 0645 0646 ind = find((ind3<0|ind3>lettersHandled)); 0647 if any(ind) 0648 ind3(ind) = lettersHandled; 0649 end 0650 ind = ind2(ind3); 0651 ix = find(ind==Nc+1); % indices to linestyle characters 0652 if any(ix) 0653 iz = strmatch(ls(ix),defaultLinestyleOrder,'exact'); 0654 if any(iz) 0655 nextLsIdx =iz(1); 0656 end 0657 end 0658 iy = find(ind<=Nc); % index to color character 0659 if any(iy) 0660 nextColorIdx = ind(iy)+1; 0661 if nextColorIdx>Nc 0662 nextColorIdx = 1; 0663 nextLsIdx = mod(nextLsIdx,Nls)+1; 0664 end 0665 end 0666 end 0667 nextLs = [defaultColorOrder(nextColorIdx) defaultLinestyleOrder{nextLsIdx}]; 0668 0669 % --- Executes on key press over pbClose with no controls selected. 0670 function pbClose_KeyPressFcn(hObject, eventdata, handles) 0671 % hObject handle to pbClose (see GCBO) 0672 % eventdata reserved - to be defined in a future version of MATLAB 0673 % handles structure with handles and user data (see GUIDATA) 0674 switch(eventdata.Key) 0675 case {'return'} 0676 if ~strcmp(get(obj,'UserData'),'Cancel') 0677 set(gcbf,'UserData','OK'); 0678 uiresume(gcbf); 0679 else 0680 delete(gcbf) 0681 end 0682 case 'escape' 0683 delete(gcbf) 0684 end 0685 0686 0687 0688 % --- Executes on button press in pbHelpButton. 0689 function pbHelpButton_Callback(hObject, eventdata, handles) 0690 % hObject handle to pbHelpButton (see GCBO) 0691 % eventdata reserved - to be defined in a future version of MATLAB 0692 % handles structure with handles and user data (see GUIDATA) 0693 0694 helpdlg(kdehelpstr,'kde1Dgui help') 0695 0696 function str = kdehelpstr 0697 str = {' KDE1DGUI gives a GUI to compute the kernel density estimate',... 0698 ' Notice that densities close to normality appear to be the easiest for the kernel', ... 0699 ' estimator to estimate and that the degree of estimation difficulty increases with ', ... 0700 ' skewness, kurtosis and multimodality.',... 0701 ' If L2~=1 KDE transforms the data before estimation. The final estimate',... 0702 ' is obtained by transforming back by a simple change of variables.',... 0703 ' Beaware of spurious spikes close to the edges when L2~=1.',... 0704 ' These spikes are due to numerical problems close to the edges.',... 0705 ' ',... 0706 ' kernel = String defining the kernel function.',.... 0707 ' hs = smooting parameter vector/matrix.',... 0708 ' (default compute from data using hsMethod)',... 0709 ' hsMethod = string defining the method to compute the smooting',... 0710 ' parameter hs',.... 0711 ' alpha = sensitivity parameter ',... 0712 ' A good choice might be alpha = 0.5 ( or 1/D)',... 0713 ' alpha = 0 Regular KDE (hs is constant)',... 0714 ' 0 < alpha <= 1 Adaptive KDE (Make hs change adaptively) ',... 0715 ' L2 = transformation parameter (L2=1 means no transformation)',... 0716 ' t(xi;L2) = xi^L2*sign(L2) for L2(i) ~= 0',... 0717 ' t(xi;L2) = log(xi) for L2(i) == 0 '}; 0718 0719 0720 0721 % --- Executes on key press over dataMenu with no controls selected. 0722 function dataMenu_KeyPressFcn(hObject, eventdata, handles) 0723 % hObject handle to dataMenu (see GCBO) 0724 % eventdata reserved - to be defined in a future version of MATLAB 0725 % handles structure with handles and user data (see GUIDATA) 0726 updateDataMenu(handles) 0727 0728 % --- If Enable == 'on', executes on mouse press in 5 pixel border. 0729 % --- Otherwise, executes on mouse press in 5 pixel border or over dataMenu. 0730 function dataMenu_ButtonDownFcn(hObject, eventdata, handles) 0731 % hObject handle to dataMenu (see GCBO) 0732 % eventdata reserved - to be defined in a future version of MATLAB 0733 % handles structure with handles and user data (see GUIDATA) 0734 updateDataMenu(handles) 0735 0736 % --- Executes on selection change in dataMenu. 0737 function dataMenu_Callback(hObject, eventdata, handles) 0738 % hObject handle to dataMenu (see GCBO) 0739 % eventdata reserved - to be defined in a future version of MATLAB 0740 % handles structure with handles and user data (see GUIDATA) 0741 0742 % Hints: contents = get(hObject,'String') returns dataMenu contents as cell array 0743 % contents{get(hObject,'Value')} returns selected item from dataMenu 0744 0745 updateDataMenu(handles) 0746 loadData(handles) 0747 0748 % --- Executes on button press in pbLoadData. 0749 function pbLoadData_Callback(hObject, eventdata, handles) 0750 % hObject handle to pbLoadData (see GCBO) 0751 % eventdata reserved - to be defined in a future version of MATLAB 0752 % handles structure with handles and user data (see GUIDATA) 0753 updateDataMenu(handles) 0754 loadData(handles) 0755 0756 0757 function loadData(handles) 0758 %LOADDATA from workspace, possibly resampled 0759 listEntries = get(handles.dataMenu,'String'); 0760 index_selected = get(handles.dataMenu,'Value'); 0761 if length(index_selected) ~= 1 0762 errordlg('You must select one variable','Incorrect Selection','modal') 0763 else 0764 var1 = listEntries{index_selected}; 0765 end 0766 doResample = get(handles.rbYes,'Value'); 0767 0768 if (doResample==1) 0769 doReplace = get(handles.rbReplace,'Value'); 0770 Nsiz = str2double(get(handles.eSampleSize,'string')); 0771 dataSelected = sample(evalin('base',var1,'errordlg(lasterr,''Error generating plots'',''modal'')'),... 0772 Nsiz,doReplace); 0773 else 0774 dataSelected = evalin('base',var1,'errordlg(lasterr,''Error generating plots'',''modal'')'); 0775 end 0776 Nsize = size(dataSelected); 0777 if prod(Nsize)~= max(Nsize) 0778 errordlg('Data selected is not a vector','Incorrect Selection','modal') 0779 else 0780 set(handles.eSampleSize,'string',int2str(length(dataSelected))); 0781 setappdata(handles.figure1,'dataSelected',dataSelected); 0782 %guidata(hObject,handles) 0783 end 0784 0785 0786 0787 % --- Executes during object creation, after setting all properties. 0788 function dataMenu_CreateFcn(hObject, eventdata, handles) 0789 % hObject handle to dataMenu (see GCBO) 0790 % eventdata reserved - to be defined in a future version of MATLAB 0791 % handles empty - handles not created until after all CreateFcns called 0792 0793 % Hint: popupmenu controls usually have a white background on Windows. 0794 % See ISPC and COMPUTER. 0795 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 0796 set(hObject,'BackgroundColor','white'); 0797 end 0798 0799 0800 % --- Executes during object creation, after setting all properties. 0801 function eBumpLinestyle_CreateFcn(hObject, eventdata, handles) 0802 % hObject handle to eBumpLinestyle (see GCBO) 0803 % eventdata reserved - to be defined in a future version of MATLAB 0804 % handles empty - handles not created until after all CreateFcns called 0805 0806 % Hint: edit controls usually have a white background on Windows. 0807 % See ISPC and COMPUTER. 0808 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 0809 set(hObject,'BackgroundColor','white'); 0810 end 0811 0812 0813 % --- Executes during object creation, after setting all properties. 0814 function eLinestyle_CreateFcn(hObject, eventdata, handles) 0815 % hObject handle to eLinestyle (see GCBO) 0816 % eventdata reserved - to be defined in a future version of MATLAB 0817 % handles empty - handles not created until after all CreateFcns called 0818 0819 % Hint: edit controls usually have a white background on Windows. 0820 % See ISPC and COMPUTER. 0821 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 0822 set(hObject,'BackgroundColor','white'); 0823 end 0824 0825 0826 % --- Executes on button press in rbNo. 0827 function rbNo_Callback(hObject, eventdata, handles) 0828 % hObject handle to rbNo (see GCBO) 0829 % eventdata reserved - to be defined in a future version of MATLAB 0830 % handles structure with handles and user data (see GUIDATA) 0831 0832 % Hint: get(hObject,'Value') returns toggle state of rbNo 0833 0834 val = get(hObject,'Value'); 0835 if val==1 0836 set(handles.rbYes,'Value',0) 0837 set(handles.rbReplace,'Value',0) 0838 dataSelected = getappdata(handles.figure1,'dataSelected'); 0839 N = length(dataSelected); 0840 if N>0 0841 set(handles.eSampleSize,'String',int2str(N)) 0842 end 0843 else 0844 set(handles.rbYes,'Value',1) 0845 end 0846 %guidata(hObject,handles) 0847 0848 % --- Executes on button press in rbYes. 0849 function rbYes_Callback(hObject, eventdata, handles) 0850 % hObject handle to rbYes (see GCBO) 0851 % eventdata reserved - to be defined in a future version of MATLAB 0852 % handles structure with handles and user data (see GUIDATA) 0853 0854 % Hint: get(hObject,'Value') returns toggle state of rbYes 0855 0856 val = get(hObject,'Value'); 0857 if val==1 0858 set(handles.rbNo,'Value',0) 0859 else 0860 set(handles.rbNo,'Value',1) 0861 set(handles.rbReplace,'Value',0) 0862 end 0863 0864 % --- Executes on button press in rbReplace. 0865 function rbReplace_Callback(hObject, eventdata, handles) 0866 % hObject handle to rbReplace (see GCBO) 0867 % eventdata reserved - to be defined in a future version of MATLAB 0868 % handles structure with handles and user data (see GUIDATA) 0869 0870 % Hint: get(hObject,'Value') returns toggle state of rbReplace 0871 if get(hObject,'Value')==0 0872 dataSelected = getappdata(handles.figure1,'dataSelected'); 0873 N = length(dataSelected); 0874 if N>0, 0875 set(handles.eSampleSize,'String',int2str(N)) 0876 end 0877 else 0878 set(handles.rbNo,'Value',0) 0879 set(handles.rbYes,'Value',1) 0880 end 0881 0882 0883 function eLinestyle_Callback(hObject, eventdata, handles) 0884 % hObject handle to eLinestyle (see GCBO) 0885 % eventdata reserved - to be defined in a future version of MATLAB 0886 % handles structure with handles and user data (see GUIDATA) 0887 0888 % Hints: get(hObject,'String') returns contents of eLinestyle as text 0889 % str2double(get(hObject,'String')) returns contents of eLinestyle as a double 0890 0891 kdePanel = getappdata(handles.figure1,'kdePanel'); 0892 kdePanel.kdeopts.linestyle = get(hObject,'String'); 0893 0894 setappdata(handles.figure1,'kdePanel',kdePanel); 0895 0896 0897 function eBumpLinestyle_Callback(hObject, eventdata, handles) 0898 % hObject handle to eBumpLinestyle (see GCBO) 0899 % eventdata reserved - to be defined in a future version of MATLAB 0900 % handles structure with handles and user data (see GUIDATA) 0901 0902 % Hints: get(hObject,'String') returns contents of eBumpLinestyle as text 0903 % str2double(get(hObject,'String')) returns contents of eBumpLinestyle as a double 0904 0905 kdePanel = getappdata(handles.figure1,'kdePanel'); 0906 kdePanel.kdeopts.bumpLinestyle = get(hObject,'String'); 0907 setappdata(handles.figure1,'kdePanel',kdePanel); 0908 0909 0910 % --- Executes on button press in plotHist. 0911 function pbPlotHist_Callback(hObject, eventdata, handles) 0912 % hObject handle to plotHist (see GCBO) 0913 % eventdata reserved - to be defined in a future version of MATLAB 0914 % handles structure with handles and user data (see GUIDATA) 0915 0916 0917 %val = get(hObject,'Value') 0918 0919 dataSelected = getappdata(handles.figure1,'dataSelected'); 0920 0921 if ~isempty(dataSelected) 0922 figure(handles.figure1) 0923 N = handles.histPanel.bins; 0924 % newplot(handles.kdeAxes) 0925 whisto(dataSelected,N,0,1) 0926 end 0927 0928 0929 0930
Comments or corrections to the WAFO group