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

📄 plotf.m

📁 Sparse Signal Representation using Overlapping Frames (matlab toolbox)
💻 M
字号:
function PlotF(F,NoText,Scale,UseK,PlotType)
% PlotF     Plot the column vectors of the one-dimensional frame F
%           The frame may be overlapping or block-oriented.
% The calling program should decide the figure number to use and clear it
% ex.  figure(1);clf;PlotF(F);     
% or   figure(1);clf;subplot(211);PlotF(Fv);subplot(212);PlotF(Fh);
% 
% PlotF(F);                     % first argument is a matrix, size NxK or NxKxP
% PlotF(FrameFile);             % or first argument is a character array
% PlotF(BuildFg(F,G));          % if F is a vector, Fg is given by F and G
% PlotF(F,NoText,Scale,UseK,PlotType);   % all possible arguments given
% -----------------------------------------------------------------------------------
% Arguments:
%  F         - This is the frame (size is NxKxP, or if P=1 NxK)
%  FrameFile - the name of the mat-file used to store the frame
%  NoText    - If 1 a more clean plot without text is made
%              If 2 a clean plot with some text is made
%              If 0 Some text is written as well
%  Scale     - How much to scale each vector to avoid vectors to plot into
%              each other, 0 (or  omitted) for automatic scaling.
%  UseK      - an array for the k-values to plot, if omitted (or 0) all are plotted
%  PlotType  - different plots are possible (default is 1):
%              1 : each frame vector a vertical line (suitable for few frame vectors)
%              2 : each frame vector as a horizontal line (ok plot with many vectors)
%              3 : time discrete signal plot
% ------------------------------------------------------------------------------------

%----------------------------------------------------------------------
% Copyright (c) 2000.  Karl Skretting.  All rights reserved.
% Hogskolen in Stavanger (Stavanger University), Signal Processing Group
% Mail:  karl.skretting@tn.his.no   Homepage:  http://www.ux.his.no/~karlsk/
% 
% HISTORY:  dd.mm.yyyy
% Ver. 1.0  29.09.2000  KS  made function
% Ver. 1.1  12.12.2000  KS  some changes
% Ver. 1.2  29.03.2001  KS  added the option to give FrameFile
% Ver. 1.3  04.10.2001  KS  a different plot is made if number of vectors to 
%                       plot is large (>15, line 98).
% Ver. 1.4  23.11.2001  KS  the second argument is changed from SizeF to NoText
%                       and arg 5 is added as PlotType
% Ver. 1.5  27.11.2002  KS: moved from ..\Frames to ..\FrameTools
%----------------------------------------------------------------------

Mfile='PlotF';

if (nargin < 1)
   disp([Mfile,': wrong number of arguments, see help.']);
   return
end

if ischar(F)
   FrameFile=F;
   if ~exist([FrameFile,'.mat'])
      disp([Mfile,': can not open FrameFile.']);
      return;
   end
   % load the following variables from FrameFile: Class, Type, Mdim, F, SizeF
   % G, Ctab, Dtab, Fbest, Savg, Mdat, PreProc, VecSel, InitialF, History, SNRtot
   load(FrameFile);
   if (Type == 'g')
      F=BuildFg(F,G);
   end
else
   SizeF=size(F); 
   FrameFile='';
end
if length(SizeF)==2; SizeF=[SizeF,1]; end;
%  check if F is a 2D or 3D frame
Mdim=(length(SizeF)-1)/2;
if Mdim~=1
   disp([Mfile,': Program is only ready for one-dimensional signals yet.']);
   return
end
%
[N,K,P]=size(F);
%  the default for the rest of the arguments
if (nargin<2);   NoText=0;    end;
if (nargin<3);   Scale=0;     end;
if (nargin<4);   UseK=(1:K);  end;
if (nargin<5);   PlotType=1;  end;
if (UseK==0);    UseK=(1:K);  end;

if P>1
   % reshape frame into K vectors of length NP
   F=reshape(permute(F,[1,3,2]),N*P,K);
end

if Scale<=0   % find Scale from F
   Scale=0.5;
   for k2=2:length(UseK)
      Scale=max(Scale,max(F(:,UseK(k2-1))-F(:,UseK(k2))));
   end
   Scale=floor(20/Scale)/20;
end

if PlotType==1;
   hold on;
   xpos=1;
   for k=UseK
      left=1;right=N*P;   % we do not want to plot leading or trailing zeros
      while ~F(left,k); 
         left=left+1; if left>right; break; end;
      end
      while ~F(right,k); 
         right=right-1; if left>right; break; end;
      end
      plot(Scale*F(left:right,k)+xpos,left:right,'-b');
      plot(xpos*ones(1,right-left+1),left:right,'-k');
      for i=left:right
         plot([xpos,Scale*F(i,k)+xpos],[i,i],'-b');
      end
      xpos=xpos+1;
   end
   
   % illustrate scale, this is not done now
   if 0 & (length(UseK)==K)
      if (N<21) & (K<21)
         % scale is only displayed if N and K are not too large
         plot(1+(0:0.1:1)*Scale,ones(1,11)*0.5,'-+b');
         text(1,0,'0');
         text(1+Scale,0,'1');
         axis([0,length(UseK)+1,-0.5,N+0.5]);
      end
   end
   % number the vectors
   if ~(NoText==1)
      xpos=1-0.1;
      ypos=N*P+(N*P)/20;
      if length(UseK)<21
         for k=UseK
            text(xpos,ypos,int2str(k));
            xpos=xpos+1;
         end
      else
         for k=1:ceil(length(UseK)/20):length(UseK)
            text(xpos,ypos,int2str(k));
            xpos=xpos+ceil(length(UseK)/20);
         end
      end
      ypos=ypos+(N*P)/20;
      axis([-1,length(UseK)+1,1-(N*P)/20,ypos]);
   end
   axis off;
   % plot line with length 1   
   if NoText==1     
      plot([0,Scale],[1-(N*P)/40,1-(N*P)/40],'-+k');
      H=text(Scale+length(UseK)/40,1-(N*P)/40,'Length of line is 1');
      set(H,'FontSize',8);
   end
   % title is plotted anyway (this may be changed/removed by calling program)
   if length(FrameFile)
      title(['The matrix F in ',FrameFile,'.mat']);
   else
      title(['The matrix F.']);
   end
   
   if P==1
      t1=['the N-dimension, N=',int2str(N)];
   else
      t1=['the NP-dimension, N=',int2str(N),' P=',int2str(P)];
      for p=1:(P-1)
         plot([0.5,0.5+length(UseK)],[N*p+0.5,N*p+0.5],':k');
      end
   end
   if ~(NoText==1)
      % plot line to illustrate the NP axis
      if N*P<40
         plot(zeros(1,N*P),1:(N*P),'-+k');
      else
         plot([0,0],[1,N*P],'-+k');
      end
      H=text(-0.1,1,int2str(1));
      set(H,'HorizontalAlignment','right');
      H=text(-0.1,N*P,int2str(N*P));
      set(H,'HorizontalAlignment','right');
      H=text(-0.25,(N*P+1)/2,t1);
      set(H,'VerticalAlignment','bottom');
      set(H,'HorizontalAlignment','center');
      set(H,'Rotation',90);
      if NoText==0
         H=text(1,ypos,['Vector number   (',Mfile,': ',datestr(now),')']);
      elseif NoText==2
         H=text(1,ypos,['Vector number']);
      end
   end
   set(gca,'ydir','reverse');
   % set(gcf,'PaperType','a4letter');
   % set(gcf,'Position',[300 300 800 600]);
   hold off;
end

if PlotType==2;
   SQ=2;   % use a squared grid for the frame vectors
   while (SQ*SQ<length(UseK)); SQ=SQ+1; end;
   dx=(N*P)*0.2;
   dy=1.2;
   hold on;
   xpos=1;
   for uk=1:length(UseK)
      k=UseK(uk);
      ypos=dy*(SQ-ceil((uk-0.5)/SQ));
      xpos=(dx+N*P)*mod(uk-1,SQ);
      left=1;right=N*P;
      plot((left:right)+xpos,Scale*F(left:right,k)+ypos,'-b');
      if ~NoText    % number the vectors
         xpos=xpos-dx/2;
         H=text(xpos,ypos,int2str(k));
         set(H,'FontSize',8);
      end
   end
   axis off;
   
   if length(FrameFile)
      title(['The vectors in matrix F in ',FrameFile,'.mat']);
   else
      title(['The vectors in matrix F.']);
   end
   % set(gcf,'PaperType','a4letter');
   % set(gcf,'Position',[300 300 800 600]);
   hold off;
end

if PlotType==3;
   SQ1=1;   % use a SQ1xSQ2 grid for the frame vectors
   % SQ2=4*SQ1; while (SQ1*SQ2<length(UseK)); SQ1=SQ1+1; SQ2=4*SQ1; end;
   SQ2=SQ1; while (SQ1*SQ2<length(UseK)); SQ1=SQ1+1; SQ2=SQ1; end;
   dx=(N*P)*0.2;
   dy=1.2;
   hold on;
   xpos=1;
   q1=1;q2=1;       % ypos and xpos
   for uk=1:length(UseK)
      k=UseK(uk);
      ypos=dy*(SQ1-q1);
      xpos=(dx+N*P)*(q2-1);
      left=1;right=N*P;
      plot((left:right)+xpos,0*(left:right)+ypos,'-b');
      for n=left:right
         plot([n+xpos,n+xpos],[ypos,Scale*F(n,k)+ypos],'-b');
         plot(n+xpos,Scale*F(n,k)+ypos,'b.');
      end
      if ~NoText    % number the vectors
         xpos=xpos-dx/2;
         H=text(xpos,ypos,int2str(k));
         set(H,'FontSize',8);
      end
      q2=q2+1;
      if q2>SQ2; q2=1; q1=q1+1; end;
   end
   axis off;
   
   if length(FrameFile)
      title(['The vectors in matrix F in ',FrameFile,'.mat']);
   else
      title(['The vectors in matrix F.']);
   end
   % set(gcf,'PaperType','a4letter');
   % set(gcf,'Position',[100 300 800 300]);
   % set(gcf,'PaperPosition',[0.2500 2.5000 8 3]);
   hold off;
end

return

⌨️ 快捷键说明

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