www.pudn.com > Closid30.rar > Cldcplot.m, change:1998-09-14,size:11376b


function cldcplot(option) 
% function cldcplot(option) 
% 
% Function to plot data or controller information 
% Options:  
% 'td': data plot time-domain 
% 'fd': data plot spectrum 
% 'fc': controller plot frequency reponse 
 
% Functions called: clobjget,clsplit,clsetcol 
 
% 30-10-1996  
% (c) Edwin van Donkelaar, Paul Van den Hof 
% Mechanical Engineering Systems and Control Group 
% Delft University of Technology 
% Last update: 19-05-1998 
%              14-09-1998: Creating white boxes around figures 
% 
%****************************************************************** 
 
global CLIDscrz CLIDmods 
z=CLIDscrz; 
 
[frmcol,txtcol,edicol,pshcol,radcol,axscol,c7,c8,c9,c10,... 
   modcol,edtcol,pubcol,putcol,chbcol,chtcol,txbcol,pstcol]=clsetcol; 
% 
%****************************************************************** 
% 
%              CONTROLLER F-RESPONSE 
% 
%****************************************************************** 
if strcmp(option,'fc') 
% Total number of controllers, active and indices  
  allcons=CLIDmods(17,:); 
  totcon=sum(CLIDmods(17,:)); 
  conact=find(CLIDmods(17,:)==1); 
% Make figure if necessary  
  if isempty(findobj('tag','CONPLOT')) 
%   Determine location and size of figure 
    posfgm=[z(3)-470 z(4)-360 430 330]; 
    fignum=figure('name','Frequency response controller','numbertitle',... 
           'off','pos',posfgm,'color',c7,... 
           'menubar','none','DefaultAxesColor',edtcol,... 
           'DefaultAxesFontsize',10,'tag','CONPLOT',... 
		   'DefaultAxesXcolor',axscol,'DefaultAxesYcolor',axscol,... 
		   'DefaultAxesBox','on'); 
    w=logspace(-3,pi,100);set(fignum,'userdata',w) 
 
% Make toolbar and set callbacks 
% File  
    oltffile=uimenu(fignum,'label','File'); 
    oltffile20=uimenu(oltffile,'Label','Print...'); 
    set(oltffile20,'callback','print -v') 
    oltffile21=uimenu(oltffile,'Label','Printer setup...'); 
    set(oltffile21,'callback','print -dsetup') 
    oltffile3=uimenu(oltffile,'Label','Close','separator','on');     
    set(oltffile3,'callback',['close(',int2str(fignum),'),handle=findobj(''tag'',''CLCONVIEW'');set(handle,''value'',0);clear handle']) 
% Options 
   oltfopt=uimenu(fignum,'label','Options'); 
    oltfopt1=uimenu(oltfopt,'Label','Auto range'); 
    set(oltfopt1,'callback','clviewev(''option'',1)') 
    oltfopt2=uimenu(oltfopt,'Label','Set axes limits...'); 
    set(oltfopt2,'callback','clviewev(''option'',2)') 
    oltfopt3=uimenu(oltfopt,'Label','Frequency range...', 'Separator','on'); 
    set(oltfopt3,'callback','clviewev(''option'',3)') 
% Style 
    oltfstyle=uimenu(fignum,'label','Style'); 
    oltfstyle1=uimenu(oltfstyle,'Label','Grid','callback','clviewev(''style'',1)');    
    oltfstyle2=uimenu(oltfstyle,'Label','Zoom','checked','on','callback','clviewev(''style'',2)'); 
    oltfstyle5=uimenu(oltfstyle,'Label','Log amplitude scale','checked','on', 'Separator','on','callback','clviewev(''style'',5)'); 
    oltfstyle6=uimenu(oltfstyle,'Label','Linear amplitude scale','callback','clviewev(''style'',6)'); 
% Help 
      cltfhlp=uimenu(fignum,'label','Help'); 
	  cltfhlp1=uimenu(cltfhlp,'label','Help Topics'); 
	  set(cltfhlp1,'call','hthelp(''clindex.htm'')'); 
 
  else 
    figure(findobj('tag','CONPLOT')) 
  end 
% Plot frequency response for all selected controllers 
  if totcon==0 
    subplot(211),cla 
    subplot(212),cla 
  else 
% Get amplitude scale  
    if strcmp(get(findobj(gcf,'label','Log amplitude scale'),'checked'),'on')         
      yscale='log'; 
    else 
      yscale='lin'; 
    end 
% Get grid option 
    if strcmp(get(findobj(gcf,'label','Grid'),'checked'),'on')         
      xgrid='on';ygrid='on'; 
    else 
      xgrid='off';ygrid='off'; 
    end 
% Clear the axes and set the figure layout  
    subplot(211),cla,set(gca,'yscale',yscale,'xscale','log','xgrid',xgrid,'ygrid',ygrid),ylabel('amplitude'),hold on 
    subplot(212),cla,set(gca,'yscale','lin','xscale','log','xgrid',xgrid,'ygrid',ygrid),ylabel('phase'),xlabel('frequency (rad/sec)'),hold on          
% Calculate and plot the frequency response 
    for i=1:totcon 
      C=get(CLIDmods(21,conact(i)),'userdata'); 
      [a,b,c,d]=clsplit(C); 
      w=get(gcf,'userdata');[mc,fc]=dbode(a,b,c,d,1,1,w); 
      subplot(211) 
      loglog(w,mc) 
      h=get(gca,'child');set(h(1),'color',modcol(conact(i),:),'visible','on'); 
% Get zoom option 
      if strcmp(get(findobj(gcf,'label','Zoom'),'checked'),'on')         
         zoom on 
      else 
         zoom off 
      end 
      subplot(212) 
      semilogx(w,fc) 
      h=get(gca,'child');set(h(1),'color',modcol(conact(i),:),'visible','on'); 
% Get zoom option 
      if strcmp(get(findobj(gcf,'label','Zoom'),'checked'),'on')         
        zoom on 
      else 
        zoom off 
      end 
    end 
  end 
else 
  [data,tit,info,p]=clobjget('data'); 
  rng1=p(1,1);rng2=p(1,2);tsamp=p(2,1);tstart=p(2,2); 
  rng1=tstart;rngN=tstart+(rng2-rng1)*tsamp; 
  datact=find(CLIDmods(2,:)==1); 
%*************************************************************** 
% 
%            DATA TIME PLOT 
% 
%*************************************************************** 
  if strcmp(option,'td')  
    if isempty(findobj('name','Time plot data')) 
% Determine location and size of figure 
      posfgm=[z(3)-470 z(4)-360 430 330]; 
      fignum=figure('name','Time plot data','numbertitle','off',... 
        'pos',posfgm,'color',c7,'menubar','none',... 
        'DefaultAxesColor',edtcol,'DefaultAxesFontsize',10,... 
        'tag','DATATPLOT',... 
        'DefaultAxesXcolor',axscol,'DefaultAxesYcolor',axscol,... 
	    'DefaultAxesBox','on'); 
 
% Make toolbar and set callbacks  
% File  
      cltffile=uimenu(fignum,'label','File'); 
      cltffile20=uimenu(cltffile,'Label','Print...'); 
      set(cltffile20,'callback','print -v') 
      cltffile21=uimenu(cltffile,'Label','Printer setup...'); 
      set(cltffile21,'callback','print -dsetup') 
      cltffile3=uimenu(cltffile,'Label','Close','separator','on');     
      set(cltffile3,'callback',['close(',int2str(fignum),'),handle=findobj(''tag'',''CLDATATVIEW'');set(handle,''value'',0);clear handle']) 
% Options 
      cltfopt=uimenu(fignum,'label','Options'); 
% Auto range 
      cltfopt1=uimenu(cltfopt,'Label','Auto range'); 
      set(cltfopt1,'callback','clviewev(''option'',1)') 
% Set axes limits  
      cltfopt2=uimenu(cltfopt,'Label','Set axes limits...'); 
      set(cltfopt2,'callback','clviewev(''option'',2)') 
% Style 
      cltfstyle=uimenu(fignum,'label','Style'); 
% Grid 
      cltfstyle1=uimenu(cltfstyle,'Label','Grid'); 
      set(cltfstyle1,'callback','clviewev(''style'',1)') 
% Zoom  
      cltfstyle2=uimenu(cltfstyle,'Label','Zoom','checked','on'); 
      set(cltfstyle2,'callback','clviewev(''style'',2)') 
% Channel 
      cltfchan=uimenu(fignum,'label','Channel'); 
      cltfchan5=uimenu(cltfchan,'Label','r1,r2,u and y'); 
% Help 
      cltfhlp=uimenu(fignum,'label','Help'); 
	  cltfhlp1=uimenu(cltfhlp,'label','Help Topics'); 
	  set(cltfhlp1,'call','hthelp(''clindex.htm'')'); 
 
    else 
       figure(findobj('name','Time plot data')) 
    end 
    if isempty(data) 
      subplot(221),cla 
      subplot(222),cla 
      subplot(223),cla 
      subplot(224),cla 
    else 
      subplot(221), 
      plot([rng1:tsamp:rngN],data(:,1),'w'),title('y'),zoom('on') 
	  h=get(gca,'child');set(h(1),'color',modcol(datact(1),:),'visible','on'); 
      subplot(222), 
      plot([rng1:tsamp:rngN],data(:,2),'w'),title('u'),zoom('on')  
      h=get(gca,'child');set(h(1),'color',modcol(datact(1),:),'visible','on'); 
      subplot(223), 
      plot([rng1:tsamp:rngN],data(:,3),'w'),xlabel('time'), 
      title('r2'),zoom('on') 
      h=get(gca,'child');set(h(1),'color',modcol(datact(1),:),'visible','on'); 
      subplot(224), 
      plot([rng1:tsamp:rngN],data(:,4),'w'),xlabel('time'), 
	  h=get(gca,'child');set(h(1),'color',modcol(datact(1),:),'visible','on'); 
      title('r1'),zoom('on') 
    end 
%*************************************************************** 
% 
%                 DATA SPECTRA 
% 
%*************************************************************** 
  elseif strcmp(option,'fd') 
    if isempty(findobj('name','Spectrum data')) 
% Determine location and size of figure 
      posfgm=[z(3)-470 30 430 330]; 
      fignum=figure('name','Spectrum data','numbertitle','off',... 
        'pos',posfgm,'color',c7,'menubar','none',... 
        'DefaultAxesColor',edtcol,'DefaultAxesFontsize',10,... 
        'tag','DATAFPLOT',... 
        'DefaultAxesXcolor',axscol,'DefaultAxesYcolor',axscol,... 
        'DefaultAxesBox','on'); 
		 
% Make toolbar and set callbacks  
% File  
      cltffile=uimenu(fignum,'label','File'); 
      cltffile20=uimenu(cltffile,'Label','Print...'); 
      set(cltffile20,'callback','print -v') 
      cltffile21=uimenu(cltffile,'Label','Printer setup...'); 
      set(cltffile21,'callback','print -dsetup') 
      cltffile3=uimenu(cltffile,'Label','Close','separator','on');     
      set(cltffile3,'callback',['close(',int2str(fignum),'),handle=findobj(''tag'',''CLDATAFVIEW'');set(handle,''value'',0);clear handle']) 
% Options 
      cltfopt=uimenu(fignum,'label','Options'); 
% Auto range 
      cltfopt1=uimenu(cltfopt,'Label','Auto range'); 
      set(cltfopt1,'callback','clviewev(''option'',1)') 
% Set axes limits  
      cltfopt2=uimenu(cltfopt,'Label','Set axes limits...'); 
      set(cltfopt2,'callback','clviewev(''option'',2)') 
% Style 
      cltfstyle=uimenu(fignum,'label','Style'); 
% Grid 
      cltfstyle1=uimenu(cltfstyle,'Label','Grid'); 
      set(cltfstyle1,'callback','clviewev(''style'',1)') 
% Zoom  
      cltfstyle2=uimenu(cltfstyle,'Label','Zoom','checked','on'); 
      set(cltfstyle2,'callback','clviewev(''style'',2)') 
% Channel 
      cltfchan=uimenu(fignum,'label','Channel'); 
      cltfchan5=uimenu(cltfchan,'Label','r1,r2,u and y'); 
% Help 
      cltfhlp=uimenu(fignum,'label','Help'); 
	  cltfhlp1=uimenu(cltfhlp,'label','Help Topics'); 
	  set(cltfhlp1,'call','hthelp(''clindex.htm'')'); 
 
    else 
      figure(findobj('name','Spectrum data')) 
    end 
    if isempty(data) 
      subplot(221),cla 
      subplot(222),cla 
      subplot(223),cla 
      subplot(224),cla 
    else 
      N=length(data);n=floor(N/2);w=[0:n]*2*pi/N; 
      sy=abs(fft(data(:,1)));sy=sy(1:n+1);su=abs(fft(data(:,2)));su=su(1:n+1); 
      sr2=abs(fft(data(:,3)));sr2=sr2(1:n+1); 
      sr1=abs(fft(data(:,4)));sr1=sr1(1:n+1);  
      subplot(221), 
      loglog(w,sy,'w'),title('y'), 
      axis([min(w)/10 max(w)*10 min(sy)/10 max(sy)*10]),zoom('on') 
      h=get(gca,'child');set(h(1),'color',modcol(datact(1),:),'visible','on'); 
      subplot(222), 
      loglog(w,su,'w'),title('u'), 
      axis([min(w)/10 max(w)*10 min(su)/10 max(su)*10]),zoom('on')  
      h=get(gca,'child');set(h(1),'color',modcol(datact(1),:),'visible','on'); 
      subplot(223), 
      loglog(w,sr2,'w'),xlabel('frequency (rad)'), 
      title('r2'),axis([min(w)/10 max(w)*10 min(sr2) max(sr2)+10]),zoom('on') 
      h=get(gca,'child');set(h(1),'color',modcol(datact(1),:),'visible','on'); 
      subplot(224), 
      loglog(w,sr1,'w'),xlabel('frequency (rad)'), 
      title('r1'),axis([min(w)/10 max(w)*10 min(sr1) max(sr1)+10]),zoom('on') 
      h=get(gca,'child');set(h(1),'color',modcol(datact(1),:),'visible','on'); 
    end 
  end 
end