⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 browse.m

📁 matlab算法集 matlab算法集
💻 M
字号:
%----------------------------------------------------------------
% Usage:       browse
%
% Description: The is the NLIB Example Browser.  It is designed
%              to simplify the task to running and viewing NLIB
%              examples and solutions to selected problems. It
%              also provides access to NLIB toolbox help, and 
%              serves as an environment for the development of 
%              user scripts.
%----------------------------------------------------------------

% Check Matlab Version

vn = 5.2;
ver = version;
vernum = str2num(ver(1:3));
if vernum < vn
   fprintf ('\nThe NLIB Example Browser requires Matlab Version 5.2');
   fprintf ('\nor later.\n\n');
   return
end

% Read data

clc
clear all

browse_r                   % nlib_run    run examples
browse_e                   % nlib_exam   view examples
browse_p                   % nlib_prob   selected problems
browse_m                   % nlib_module NLIB modules
browse_f                   % nlib_fun    NLIB functions
browse_u                   % nlib_user   user examples 

%----------------------------------------------------------------
% Top Level Menu
%----------------------------------------------------------------

hf_1 = figure('NumberTitle','off','Name',...
'                                     NLIB Example Browser (MATLAB)');


%set (gcf,'MenuBar',menubar)
%set (gcf,'MenuBar','none')
 
% Full screen

% screen = get (0,'ScreenSize');
% screen(4) = round(0.92*screen(4)); 
% set (gcf,'Position',screen)

% Top Level Menu

hm_1 = uimenu (hf_1,'Label','Run');
hm_2 = uimenu (hf_1,'Label','View');
hm_3 = uimenu (hf_1,'Label','User');
hm_4 = uimenu (hf_1,'Label','NLIB Help');
hm_5 = uimenu (hf_1,'Label','Exit','Callback',...
               'close; clc; return');

%----------------------------------------------------------------
% Run Menu
%----------------------------------------------------------------

hm_11 = uimenu (hm_1,'Label','Examples');
hm_12 = uimenu (hm_1,'Label','Selected Problems','Separator','on');

% Run Examples 

for i = 1 : 10
   run1(i) = uimenu (hm_11,'Label',sprintf('Chapter %g',i));
end
run1(11) = uimenu (hm_11,'Label','Appendix 1','Separator','on');

[m,n] = size (nlib_run);
num_exam = zeros(11,1);               % number of examples 
for i = 1 : m

   cback = sprintf (...
     'set(gcf,''Visible'',''off''); %s; set(gcf,''Visible'',''on'')',...
      nlib_run(i,1:8));
   label = deblank(nlib_run(i,10:n));

% Chapters 1-9

   for j = 1 : 9
      s = sprintf('e%g',j);
      if (strcmp(nlib_run(i,1:2),s)) & (nlib_run(i,3) ~= '0')
         num_exam(j) = num_exam(j) + 1;
         run11(num_exam(j)) = uimenu (run1(j),'Label',label,...
                              'Callback',cback);
         if nlib_run(i,9) == '.'
            set (run11(num_exam(j)),'Separator','on')
         end 
      end
   end

% Chapter 10

   if (nlib_run(i,1:3) == 'e10')              
      num_exam(10) = num_exam(10) + 1;
      run11(num_exam(10)) = uimenu (run1(10),'Label',label,...
                           'Callback',cback);
      if nlib_run(i,9) == '.'
         set (run11(num_exam(10)),'Separator','on')
      end
   end

% Appendix 1

   if (nlib_run(i,1:2) == 'a1')               
      num_exam(11) = num_exam(11) + 1;
      run11(num_exam(11)) = uimenu (run1(11),'Label',label,...
                           'Callback',cback);
      if nlib_run(i,9) == '.'
         set (run11(num_exam(11)),'Separator','on')
      end
   end
end

% Run Problems 

for i = 1 : 10
   run2(i) = uimenu (hm_12,'Label',sprintf('Chapter %g',i));
end

[m,n] = size (nlib_prob);
num_prob = zeros(10,1);               % number of examples 
for i = 1 : m

%   cback = sprintf ('close; %s; browse',nlib_prob(i,1:8));
   cback = sprintf (...
     'set(gcf,''Visible'',''off''); %s; set(gcf,''Visible'',''on'')',...
      nlib_prob(i,1:8));
   label = deblank(nlib_prob(i,10:n));

% Chapters 1-9

   for j = 1 : 9
      s = sprintf('prob%g',j);
      if (strcmp(nlib_prob(i,1:5),s)) & (nlib_prob(i,6) ~= '0')
         num_prob(j) = num_prob(j) + 1;
         run21(num_prob(j)) = uimenu (run2(j),'Label',label,...
                              'Callback',cback);
      end
   end

% Chapter 10

   if (nlib_prob(i,1:6) == 'prob10')              
      num_prob(10) = num_prob(10) + 1;
      run21(num_prob(10)) = uimenu (run2(10),'Label',label,...
                           'Callback',cback);
   end
end

%----------------------------------------------------------------
% View Menu
%----------------------------------------------------------------

hm_21 = uimenu (hm_2,'Label','Examples');
hm_22 = uimenu (hm_2,'Label','Selected Problems','Separator','on');

% View Examples 

for i = 1 : 10
   view1(i) = uimenu (hm_21,'Label',sprintf('Chapter %g',i));
end
view1(11) = uimenu (hm_21,'Label','Appendix 1','Separator','on');

% Construct callbacks for viewing examples

[m,n] = size (nlib_exam);
num_exam = zeros(11,1);               % number of examples 
for i = 1 : m

   cback = sprintf (...
     'set(gcf,''Visible'',''off''); edit %s; set(gcf,''Visible'',''on'')',...
      nlib_exam(i,1:8));
   label = deblank(nlib_exam(i,10:n));

% Chapters 1-9

   for j = 1 : 9
      s = sprintf('e%g',j);
      if ((strcmp(nlib_exam(i,1:2),s)) & (nlib_exam(i,3) ~= '0')) | ...
         ((strcmp(nlib_exam(i,1:3),'fun')) & ...
         (~strcmp(nlib_exam(i,4),'a')) & ...
         (~strcmp(nlib_exam(i,6),'0')) & ...
         (strcmp(nlib_exam(i,5),s(2)))) | ...
         ((strcmp(nlib_exam(i,1:4),'data')) & ...  
         (nlib_exam(i,5) == s(2)) & (nlib_exam(i,6) ~= '0')) 
         num_exam(j) = num_exam(j) + 1;
         view11(num_exam(j)) = uimenu (view1(j),'Label',label,...
                              'Callback',cback);
         if (nlib_exam(i,9) == '.')
            set (view11(num_exam(j)),'Separator','on');
         end
      end
   end

% Chapter 10

   if (nlib_exam(i,1:3) == 'e10') | ...
      ((strcmp(nlib_exam(i,1:3),'fun')) & ...
      (strcmp(nlib_exam(i,5:6),'10'))) | ...
      (strcmp(nlib_exam(i,1:6),'data10'))                   
      num_exam(10) = num_exam(10) + 1;
      view11(num_exam(10)) = uimenu (view1(10),'Label',label,...
                           'Callback',cback);
      if (nlib_exam(i,9) == '.')
         set (view11(num_exam(10)),'Separator','on');
      end
   end

% Appendix 1

   if (nlib_exam(i,1:2) == 'a1') | ...
      (strcmp(nlib_exam(i,1:4),'funa')) 
      num_exam(11) = num_exam(11) + 1;
      view11(num_exam(11)) = uimenu (view1(11),'Label',label,...
             'Callback',cback);
      if (nlib_exam(i,9) == '.')
         set (view11(num_exam(11)),'Separator','on');
      end
   end
end

% View Problems 

for i = 1 : 10
   view2(i) = uimenu (hm_22,'Label',sprintf('Chapter %g',i));
end

% Construct callbacks for viewing selected problems

[m,n] = size (nlib_prob);
num_prob = zeros(10,1);               % number of examples 
for i = 1 : m

   cback = sprintf (...
     'set(gcf,''Visible'',''off''); edit %s; set(gcf,''Visible'',''on'')',...
      nlib_prob(i,1:8));
   label = deblank(nlib_prob(i,9:n));

% Chapters 1-9

   for j = 1 : 9
      s = sprintf('prob%g',j);
      if ((strcmp(nlib_prob(i,1:5),s)) & (nlib_prob(i,6) ~= '0')) | ...
         (strcmp(nlib_prob(i,1:3),'fun') & (nlib_prob(i,4) == s(5))) | ...
         (strcmp(nlib_prob(i,1:8),'quadroot') & (j == 1)) | ...
         (strcmp(nlib_prob(i,1:5),'randf') & (j == 1)) | ...
         (strcmp(nlib_prob(i,1:3),'jac') & (j == 2)) | ...
         (strcmp(nlib_prob(i,1:6),'expfit') & (j == 4))
          num_prob(j) = num_prob(j) + 1;
          view21(num_prob(j)) = uimenu (view2(j),'Label',label,...
                              'Callback',cback);
      end
   end

% Chapter 10

   if (nlib_prob(i,1:6) == 'prob10')              
      num_prob(10) = num_prob(10) + 1;
      view21(num_prob(10)) = uimenu (view2(10),'Label',label,...
                           'Callback',cback);
   end
end

%----------------------------------------------------------------
% User Menu
%----------------------------------------------------------------

% Run User Scripts

[m,n] = size (nlib_user);
hm_31 = uimenu (hm_3,'Label','Run User Scripts');                  
[m,n] = size(nlib_user);
for i = 1 : m
   label = deblank(nlib_user(i,:));

   cback = sprintf (...
     'set(gcf,''Visible'',''off''); %s; set(gcf,''Visible'',''on'')',label);

   run31(i) = uimenu (hm_31,'Label',label,'Callback',cback);
end

% View User Scripts                  
                  
hm_32 = uimenu (hm_3,'Label','View/Edit User Scripts');
for i = 1 : m

   cback = sprintf (...
     'set(gcf,''Visible'',''off''); edit %s; set(gcf,''Visible'',''on'')',...
      deblank(nlib_user(i,:)));

   label = deblank(nlib_user(i,:));
   view31(i) = uimenu (hm_32,'Label',label,'Callback',cback);
end

% Create User Script

hm_33 = uimenu (hm_3,'Label','Create User Script',...
               'Callback','close; edit; browse',...
               'Separator','on');

% Add Script to Browser

cbk = ['[ufile,upath] = uigetfile (''*.*'',''Select script''); '...
       'if ufile ~= 0 '...
       '   nlib_user = useradd (ufile); '...
       'end; '...
       'close; browse'];
   
hm_34 = uimenu (hm_3,'Label','Add Script to Browser',...
                    'Callback',cbk);

% Remove Script from Browser

%cback = ['[nlib_user,s] = userdel(nlib_user); '...
%         'close; '...
%         'browse'];    

cback = ['userdel; close; browse'];    

hm_35 = uimenu (hm_3,'Label','Remove Script from Browser',...
                     'Callback',cback);


%----------------------------------------------------------------
% Help Menu
%----------------------------------------------------------------

hm_41 = uimenu (hm_4,'Label','NLIB Toolbox Help');

% Toolbox Help

[m,n] = size(nlib_module);
num_fun = zeros(10,1);               % number of functions

for i = 1 : 10
   nhelp(i) = uimenu (hm_41,'Label',sprintf('%s',nlib_module(i,1:n)));
end

[p,q] = size(nlib_fun);

for i = 1 : p

   cback = sprintf (...
     'set(gcf,''Visible'',''off''); clc; help %s; wait; more off; set(gcf,''Visible'',''on'')',...
      nlib_fun(i,4:12));

   label = [nlib_fun(i,4:12) nlib_fun(i,14:q)];

% Chapters 1-9

   for j = 1 : 9
      s = sprintf('%g',j);
      if strcmp(nlib_fun(i,1),s) & ~strcmp(nlib_fun(i,2),'0')
         num_fun(j) = num_fun(j) + 1;
         nhelp11(num_fun(j)) = uimenu (nhelp(j),'Label',label,...
                              'Callback',cback);
         if nlib_fun(i,13) == '.'
            set (nhelp11(num_fun(j)),'Separator','on')
         end
      end
   end

% Chapter 10

   s = '10';
   if strcmp(nlib_fun(i,1:2),s) 
      num_fun(10) = num_fun(10) + 1;
      nhelp11(num_fun(10)) = uimenu (nhelp(10),'Label',label,...
                           'Callback',cback);
      if nlib_fun(i,13) == '.'
         set (nhelp11(num_fun(10)),'Separator','on')
      end
   end

end

% Software Updates

cback = 'set(gcf,''Visible'',''off''); edit browse_s.m; set(gcf,''Visible'',''on'')';

%hm_42 = uimenu (hm_4,'Label','NLIB Update','Callback',cback,...
%        'Separator','on');

hm_42 = uimenu (hm_4,'Label','NLIB Updates','Separator','on');

hm_421 = uimenu (hm_42,'Label','General information','Callback',cback);

cback1 = 'set(gcf,''Visible'',''off''); web http://sunspot.ece.clarkson.edu/~schillin/nlib.htm; set(gcf,''Visible'',''on'')';

hm_422 = uimenu (hm_42,'Label','Download NLIB updates','Callback',cback1);

% User Tips

cback = 'set(gcf,''Visible'',''off''); edit browse_t.m; set(gcf,''Visible'',''on'')';

hm_43 = uimenu (hm_4,'Label','User Tips','Callback',cback,...
                'Separator','on');
        
% About
           
cback = 'set(gcf,''Visible'',''off''); edit browse_a.m; set(gcf,''Visible'',''on'')';

hm_44 = uimenu (hm_4,'Label','About','Callback',cback,...
        'Separator','on');


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -