annotate toolboxes/FullBNT-1.0.7/KPMtools/plot_matrix.m @ 0:e9a9cd732c1e tip

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