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

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