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