annotate _FullBNT/KPMtools/plot_matrix.m @ 9:4ea6619cb3f5 tip

removed log files
author matthiasm
date Fri, 11 Apr 2014 15:55:11 +0100
parents b5b38998ef3b
children
rev   line source
matthiasm@8 1 function plot_matrix(G, bw)
matthiasm@8 2 % PLOT_MATRIX Plot a 2D matrix as a grayscale image, and label the axes
matthiasm@8 3 %
matthiasm@8 4 % plot_matrix(M)
matthiasm@8 5 %
matthiasm@8 6 % For 0/1 matrices (eg. adjacency matrices), use
matthiasm@8 7 % plot_matrix(M,1)
matthiasm@8 8
matthiasm@8 9 if nargin < 2, bw = 0; end
matthiasm@8 10
matthiasm@8 11 if 0
matthiasm@8 12 imagesc(G)
matthiasm@8 13 %image(G)
matthiasm@8 14 %colormap([1 1 1; 0 0 0]); % black squares on white background
matthiasm@8 15 %colormap(gray)
matthiasm@8 16 grid on
matthiasm@8 17 n = length(G);
matthiasm@8 18
matthiasm@8 19 % shift the grid lines so they don't intersect the squares
matthiasm@8 20 set(gca,'xtick',1.5:1:n);
matthiasm@8 21 set(gca,'ytick',1.5:1:n);
matthiasm@8 22
matthiasm@8 23 % Turn off the confusing labels, which are fractional
matthiasm@8 24 % Ideally we could shift the labels to lie between the axis lines...
matthiasm@8 25 % set(gca,'xticklabel', []);
matthiasm@8 26 % set(gca,'yticklabel', []);
matthiasm@8 27 else
matthiasm@8 28 % solution provided by Jordan Rosenthal <jr@ece.gatech.edu>
matthiasm@8 29 % You can plot the grid lines manually:
matthiasm@8 30 % This uses the trick that a point with a value nan does not get plotted.
matthiasm@8 31 imagesc(G);
matthiasm@8 32 if bw
matthiasm@8 33 colormap([1 1 1; 0 0 0]);
matthiasm@8 34 end
matthiasm@8 35 n = length(G);
matthiasm@8 36 x = 1.5:1:n;
matthiasm@8 37 x = [ x; x; repmat(nan,1,n-1) ];
matthiasm@8 38 y = [ 0.5 n+0.5 nan ].';
matthiasm@8 39 y = repmat(y,1,n-1);
matthiasm@8 40 x = x(:);
matthiasm@8 41 y = y(:);
matthiasm@8 42 line(x,y,'linestyle',':','color','k');
matthiasm@8 43 line(y,x,'linestyle',':','color','k');
matthiasm@8 44 set(gca,'xtick',1:n)
matthiasm@8 45 set(gca,'ytick',1:n)
matthiasm@8 46 end
matthiasm@8 47
matthiasm@8 48