cbanapar.m
上传用户:haiyisale
上传日期:2013-01-09
资源大小:3246k
文件大小:12k
源码类别:

波变换

开发平台:

Matlab

  1. function varargout = cbanapar(option,fig,varargin)
  2. %CBANAPAR Callbacks for wavelet analysis parameters.
  3. %   VARARGOUT = CBANAPAR(OPTION,VARARGIN)
  4. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 04-May-98.
  5. %   Last Revision: 05-Jun-2003.
  6. %   Copyright 1995-2004 The MathWorks, Inc.
  7. %   $Revision: 1.7.4.2 $  $Date: 2004/03/15 22:39:43 $
  8. switch option
  9.     case 'no_pop'
  10.         pop_liste  = varargin{1};
  11.         [Pop_Wav_Fam,Pop_Wav_Num,Pop_Lev] = utanapar('handles',fig,'pop');
  12.         ind = wcommon(pop_liste,[Pop_Wav_Fam,Pop_Wav_Num,Pop_Lev]);
  13.         pop_liste(ind) = [];
  14.         varargout{1} = pop_liste;
  15.     case 'cba_fam'
  16.         if nargin>3   % VERSION 3: Inputs = (option , fig, eventdata, handles)
  17.             handles = varargin{2};
  18.             Pop_Wav_Fam = handles.Pop_Wav_Fam;
  19.             Pop_Wav_Num = handles.Pop_Wav_Num;
  20.         else          % VERSION 2 & 3: Inputs = (option , fig, [Pop_Wav_Fam, Pop_Wav_Num])
  21.             Pop_Wav_Fam = varargin{1}(1);
  22.             Pop_Wav_Num = varargin{1}(2);
  23.         end
  24.         numf = get(Pop_Wav_Fam,'Value');
  25.         strf = get(Pop_Wav_Fam,'String');
  26.         strf = noblank(strf(numf,:));
  27.         tab  = wavemngr('fields',{'fsn',strf},'tabNums');
  28.         nbNUM = size(tab,1);
  29.         switch  nbNUM;
  30.             case 0    , vis = 'off'; strf = 'no';
  31.             case 1    , if strcmp(noblank(tab(1,:)),'no') , vis = 'off'; end
  32.             otherwise , vis = 'on';
  33.         end
  34.         if strcmp(vis,'off')
  35.             set(Pop_Wav_Num,'Visible',vis,'String',tab,'Value',1);
  36.         else
  37.             set(Pop_Wav_Num,'String',tab,'Value',1,'Visible',vis);
  38.         end
  39.     case 'set'
  40.         nbarg = length(varargin);
  41.         if nbarg<1 , return; end
  42.         [Txt_Data_NS,Edi_Data_NS,Pop_Wav_Fam,Pop_Wav_Num,Pop_Lev] = utanapar('handles',fig);
  43.         for k = 1:2:nbarg
  44.            argType = varargin{k};
  45.            argVal  = varargin{k+1};
  46.            switch argType
  47.              case 'typ'
  48.                 set(Txt_Data_NS,'String',[argVal '  (Size)']);
  49.              case 'n_s' ,
  50.                 siz = argVal{2};
  51.                 dim = length(siz);
  52.                 n_s = [argVal{1} '  (' ];
  53.                 if   dim==1
  54.                   n_s = [n_s,int2str(siz) ')'];
  55.                 else
  56.                   n_s = [n_s,int2str(siz(2)) 'x' int2str(siz(1)) ')'];
  57.                 end
  58.                 set(Edi_Data_NS,'String',n_s);                
  59.              case 'nam' , set(Edi_Data_NS,'String',argVal);
  60.              case 'fam' , setProperties(Pop_Wav_Fam,argVal);
  61.              case 'num' , setProperties(Pop_Wav_Num,argVal);
  62.              case 'wav' , setWname(Pop_Wav_Fam,Pop_Wav_Num,argVal);
  63.              case 'lev' , setProperties(Pop_Lev,argVal);
  64.            end
  65.         end
  66.     case 'get'
  67.         nbarg = length(varargin);
  68.         if nbarg<1 , return; end
  69.         [Txt_Data_NS,Edi_Data_NS,Pop_Wav_Fam,Pop_Wav_Num,Pop_Lev] = utanapar('handles',fig);
  70.         for k = 1:nbarg
  71.            outType = varargin{k};
  72.            switch outType
  73.              case 'wav'
  74.                  wf   = get(Pop_Wav_Fam,{'Style','String','Value'});
  75.                  if isequal(wf{1},'edit')
  76.                     fam  = wf{2};
  77.                  else
  78.                     fam  = wf{2}(wf{3},:);
  79.                  end
  80.                  fam = noblank(fam);
  81.                  wf = get(Pop_Wav_Num,{'Style','String','Value'});
  82.                  if ~isequal(wf{1},'edit')
  83.                      strn = wf{2};                    
  84.                      if ~isempty(strn)
  85.                          strn = noblank(strn(wf{3},:));
  86.                          if strcmp(strn,'no') , strn = ''; end
  87.                      else
  88.                          strn = '';
  89.                      end
  90.                 else
  91.                     strn = noblank(wf{2});
  92.                     if strcmp(strn,'no') , strn = ''; end
  93.                 end                
  94.                 varargout{k} = [fam strn];
  95.              case 'lev'
  96.                  levPar = get(Pop_Lev,{'Style','String','Value'});
  97.                  if ~isequal(levPar{1},'edit')
  98.                      varargout{k} = wstr2num(levPar{2}(levPar{3},:));
  99.                  else
  100.                      varargout{k} = wstr2num(levPar{2});
  101.                  end
  102.  
  103.              case 'levmax' ,  varargout{k} = size(get(Pop_Lev,'String'),1);
  104.              
  105.              case 'nam'
  106.                 varargout{k} = get(Edi_Data_NS,'String');
  107.            end
  108.         end
  109.     case 'enable'
  110.         ena = varargin{1};
  111.         [Pop_Wav_Fam,Pop_Wav_Num,Pop_Lev] = utanapar('handles',fig,'fam','num','lev');
  112.         handles = [Pop_Wav_Fam,Pop_Wav_Num,Pop_Lev];
  113.         set(handles(ishandle(handles)),'enable',ena);
  114.     case 'cba_num'
  115.         switch nargin
  116.             case {3,5}    % VERSION 2 & 3: Inputs = (option , fig, [Pop_Wav_Fam, Pop_Wav_Num])
  117.                 Pop_Wav_Fam = varargin{1}(1);
  118.                 Pop_Wav_Num = varargin{1}(2);
  119.                 if length(varargin)>1 , % varargin{2} NOT USED
  120.                     ena_hdl = varargin{3};
  121.                 else
  122.                     ena_hdl = [];
  123.                 end
  124.             case 4   % VERSION 3: Inputs = (option , fig, eventdata, handles)
  125.                 handles = varargin{2};
  126.                 Pop_Wav_Fam = handles.Pop_Wav_Fam;
  127.                 Pop_Wav_Num = handles.Pop_Wav_Num;           
  128.         end
  129.         lst  = get(Pop_Wav_Num,'String');
  130.         val  = get(Pop_Wav_Num,'Value');
  131.         item = deblankl(lst(val,:));
  132.         if strcmp(item,'**')
  133.             pos = get(Pop_Wav_Num,'Position');
  134.             uni = get(Pop_Wav_Num,'Units');
  135.             if ~isempty(ena_hdl)
  136.                 ena_hdl = findobj(ena_hdl,'flat','Enable','on');
  137.                 set(ena_hdl,'Enable','off');
  138.             end
  139.             set(Pop_Wav_Fam,'Enable','off');
  140.             set(Pop_Wav_Num,'Visible','off');
  141.             edi_num = uicontrol(...
  142.                         'Parent',get(Pop_Wav_Num,'Parent'), ...
  143.                         'style','edit',         ...
  144.                         'Units',uni,            ...
  145.                         'Position',pos,         ...
  146.                         'BackGroundColor','w',  ...
  147.                         'Interruptible','Off',  ...
  148.                         'string',[]             ...
  149.                         );
  150.             hdl_str = num2mstr([Pop_Wav_Fam;Pop_Wav_Num;edi_num;ena_hdl]);
  151.             cba = [mfilename '(''ok_num'',' num2mstr(fig) ',' hdl_str  ');'];
  152.             set(edi_num,'Callback',cba);
  153.         end
  154.     case 'ok_num'
  155.         Pop_Wav_Fam = varargin{1}(1);
  156.         Pop_Wav_Num = varargin{1}(2);
  157.         edi     = varargin{1}(3);
  158.         if length(varargin{1})>3 , 
  159.             ena_hdl = varargin{1}(4:end);
  160.         else
  161.             ena_hdl = [];
  162.         end
  163.         rmax  = 16;
  164.         nmax  = 45;
  165.         tmp   = get(Pop_Wav_Fam,{'String','value'});
  166.         w_fam = deblankl(tmp{1}(tmp{2},:));
  167.         [typNums,w_fileName] ...
  168.             = wavemngr('fields',{'fsn',w_fam}, 'typNums','file');
  169.         [dummy,filename,ext] = fileparts(w_fileName);        
  170.       
  171.         item = deblank(get(edi,'String'));        
  172.         err = 0; ok = 1; val = 0;
  173.         switch typNums
  174.           case {'integer','real'}
  175.             if isempty(ext)
  176.                try
  177.                  maxNum = feval(filename);
  178.                  if length(maxNum)==1 , nmax = maxNum; end
  179.                end
  180.             end
  181.             num = wstr2num(item);
  182.             if isempty(num) | (num<1) | (num>nmax) , err = 1; end
  183.             if ~err
  184.                 if isequal(typNums,'integer') , err = num~=fix(num); end
  185.             end          
  186.             if err , ok = 0; val = 1; end
  187.           case 'string'
  188.             try
  189.               bounds = wavemngr('fields',{'fsn',w_fam}, 'bounds');
  190.               nbpoints = 10;
  191.               wname  = [w_fam,item];
  192.               feval(filename,bounds(1),bounds(2),nbpoints,wname);
  193.             catch
  194.               err = 1; ok = 0; val = 1;
  195.             end          
  196.         end
  197.         if ~err
  198.             lst = get(Pop_Wav_Num,'String');
  199.             [r,c] = size(lst);
  200.             switch typNums
  201.               case {'integer','real'}
  202.                 for k=1:r-1
  203.                     num_k = wstr2num(lst(k,:));
  204.                     if num==num_k
  205.                       ok  = 0;
  206.                       val = k;
  207.                       break;
  208.                     elseif  num<num_k
  209.                       ok  = 1;
  210.                       val = k;
  211.                       item = getItem(num,typNums);
  212.                       if k==1 , lst_beg = item;
  213.                       else    , lst_beg = strvcat(lst(1:k-1,:),item);
  214.                       end
  215.                       if r<rmax ,    middleLST = lst(k:r-1,:);
  216.                       elseif k<r-1 , middleLST = lst(k:r-2,:);
  217.                       else ,         middleLST = '';
  218.                       end
  219.                       lst = strvcat(lst_beg,middleLST,lst(r,:));
  220.                       break;
  221.                     end
  222.                 end
  223.                 if val==0 ,
  224.                     ok  = 1;
  225.                     val = r;
  226.                     item = getItem(num,typNums);
  227.                     if r==rmax , r = r-1; end
  228.                     lst = strvcat(lst(1:r-1,:),item,lst(r,:));
  229.                 end
  230.               case 'string'                
  231.                 k = strmatch(item,lst,'exact');
  232.                 if ~isempty(k)
  233.                     ok  = 0;
  234.                     val = k;
  235.                 else
  236.                     ok  = 1;
  237.                     val = r;
  238.                     if r==rmax , r = r-1; end
  239.                     lst = strvcat(lst(1:r-1,:),item,lst(r,:));
  240.                 end
  241.             end
  242.         end
  243.         if ok
  244.             set(Pop_Wav_Num,'string',lst,'Value',val,'visible','on');
  245.         else
  246.             set(Pop_Wav_Num,'Value',val,'visible','on');
  247.         end
  248.         delete(edi)
  249.         set(Pop_Wav_Fam,'Enable','on');
  250.         if ~isempty(ena_hdl) , set(ena_hdl,'Enable','on'); end
  251.         if err
  252.            wwarndlg('Invalid Wavelet Number!','Select Wavelet Number','modal');
  253.         end
  254.     otherwise
  255.         errargt(mfilename,'Unknown Option','msg');
  256.         error('*');
  257. end
  258. %---------------------------------------%
  259. % Internal Function(s)                  %
  260. %---------------------------------------%
  261. function s = noblank(x)
  262. if ~isempty(x)
  263.     s = x(x~=' ' & x~=0);
  264. else
  265.     s = '';
  266. end
  267. %---------------------------------------%
  268. function item = getItem(num,typNums)
  269. switch typNums
  270.     case 'integer'
  271.       item = sprintf('%.0f',num);
  272.     case 'real'
  273.       item = sprintf('%.15f',num);
  274.       while item(end)=='0' , item(end) = []; end
  275.       if length(item)>0 & item(end)=='.'
  276.           item = [item '0'];
  277.       end
  278. end
  279. %---------------------------------------%
  280. function setProperties(h,argVal)
  281. if iscell(argVal)
  282.     set(h,argVal{:});
  283. else
  284.     set(h,'Value',argVal);
  285. end
  286. %----------------------------------------------------------------------%
  287. function varargout = setWname(Pop_Wav_Fam,Pop_Wav_Num,wname)
  288. [i_fam,i_num,wav_fam,num_str,tab_num,add_num] = wavemngr('indw',wname);
  289. tabfam_loc = get(Pop_Wav_Fam,'String');
  290. for k = 1:size(tabfam_loc,1);
  291.     if strcmp(wav_fam,deblank(tabfam_loc(k,:)))
  292.         i_fam_loc = k;
  293.         break
  294.     end
  295. end
  296. lnum = size(tab_num,1);
  297. if lnum==1 & isempty(num_str) , tab_num = ''; end
  298. if add_num
  299.     if lnum==1
  300.         tab_num = num_str;
  301.     else
  302.         tab_num = strvcat(tab_num(1:lnum-1,:),num_str,tab_num(lnum,:));
  303.     end
  304. end
  305. if isempty(tab_num)
  306.     tab_num = 'no'; vis  = 'off';
  307. else
  308.     vis  = 'on';
  309. end
  310. %%% MiMi : BUG MATLAB %%%
  311. tmp = get(Pop_Wav_Fam,'String');
  312. rrr = size(tmp,1);
  313. set(Pop_Wav_Fam,'Value',rrr);
  314. pause(0.01)
  315. set(Pop_Wav_Fam,'Value',i_fam_loc);
  316. set(Pop_Wav_Num,'Visible',vis,'String',tab_num,'Value',i_num);
  317. if nargout>0
  318.     varargout = {wav_fam,tab_num,i_fam,i_num,i_fam_loc};
  319. end
  320. %----------------------------------------------------------------------%