Home > wafo > kdetools > kde2dgui.m

kde2dgui

PURPOSE ^

GUI to Kernel Density Estimator in two dimensions.

SYNOPSIS ^

varargout = kde2dgui(varargin)

DESCRIPTION ^

 KDE2DGUI GUI to Kernel Density Estimator in two dimensions.
 
   CALL:  kde2dgui
 
  Example:
 
   data = wraylrnd(1,1000,2)
   kde2dgui
 
  See also  kde1dgui, kde

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

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

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group


Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003