Home > utility > diffPlot.m

diffPlot

PURPOSE ^

diffPlot: View the difference of two vectors

SYNOPSIS ^

function diffPlot(vec1, vec2)

DESCRIPTION ^

diffPlot: View the difference of two vectors
    Usage: diffPlot(vec1, vec2)

    For example:
        x = randperm(10);
        y = x.^(1/1000000000).^1000000000;
        diffPlot(x, y);

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function diffPlot(vec1, vec2)
0002 %diffPlot: View the difference of two vectors
0003 %    Usage: diffPlot(vec1, vec2)
0004 %
0005 %    For example:
0006 %        x = randperm(10);
0007 %        y = x.^(1/1000000000).^1000000000;
0008 %        diffPlot(x, y);
0009 
0010 %    Roger Jang, 20070706
0011 
0012 if nargin<1, selfdemo; return ;end
0013 
0014 vec1=vec1(:);
0015 vec2=vec2(:);
0016 name1=inputname(1);
0017 name2=inputname(2);
0018 
0019 subplot(2,1,1);
0020 plot(1:length(vec1), vec1, '-', 1:length(vec2), vec2, '-');
0021 grid on
0022 title(sprintf('Curves of %s and %s\n', name1, name2));
0023 legend(name1, name2);
0024 subplot(2,1,2);
0025 minLen=min(length(vec1), length(vec2));
0026 plot(1:minLen, abs(vec1(1:minLen)-vec2(1:minLen)), '-');
0027 maxAbsDiff=max(abs(vec1(1:minLen)-vec2(1:minLen)));
0028 grid on
0029 title(sprintf('Abs. diff. of %s and %s, with maxAbsDiff=%g\n', name1, name2, maxAbsDiff));
0030 
0031 % ====== Self demo
0032 function selfdemo
0033 x = randperm(10);
0034 y = x.^(1/1000000000).^1000000000;
0035 diffPlot(x, y);

Generated on Tue 01-Jun-2010 09:50:34 by m2html © 2003