Home > utility > barPlot.m

barPlot

PURPOSE ^

barPlot: Plot of 1-D data as bars and texts

SYNOPSIS ^

function barPlot(data, xTickLabel)

DESCRIPTION ^

 barPlot: Plot of 1-D data as bars and texts
    Usage: barPlot(data, xTickLabel)

    For example:
        data = rand(1, 10);
        dataNum = length(data);
        xTickLabel={};
        for i=1:dataNum
            xTickLabel={xTickLabel{:}, sprintf('第 %d 筆資料', i)};
        end
        barPlot(data, xTickLabel);

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function barPlot(data, xTickLabel)
0002 % barPlot: Plot of 1-D data as bars and texts
0003 %    Usage: barPlot(data, xTickLabel)
0004 %
0005 %    For example:
0006 %        data = rand(1, 10);
0007 %        dataNum = length(data);
0008 %        xTickLabel={};
0009 %        for i=1:dataNum
0010 %            xTickLabel={xTickLabel{:}, sprintf('第 %d 筆資料', i)};
0011 %        end
0012 %        barPlot(data, xTickLabel);
0013 
0014 %    Roger Jang, 20071009
0015 
0016 if nargin<1, selfdemo; return; end
0017 
0018 dataNum=length(data);
0019 subplot(2,1,1);
0020 bar(1:dataNum, data);
0021 set(gca, 'xticklabel', []);
0022 grid on;
0023 
0024 for i=1:dataNum
0025     text(i, 0, xTickLabel{i});
0026 end
0027 h = findobj(gcf, 'type', 'text');
0028 set(h, 'rot', 90, 'horizontal', 'right');
0029 
0030 % ====== Self demo
0031 function selfdemo
0032 data = rand(1, 10);
0033 dataNum = length(data);
0034 xTickLabel={};
0035 for i=1:dataNum
0036     xTickLabel={xTickLabel{:}, sprintf('第 %d 筆資料', i)};
0037 end
0038 feval(mfilename, data, xTickLabel);

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