view spyh.m @ 443:12db86a8ec7b

Fix bug in spyh() when the matix has no non-zero elements.
author Jonatan Werpers <jonatan@werpers.com>
date Sun, 19 Mar 2017 13:39:49 +0100
parents 5cb99f56f55e
children
line wrap: on
line source

% spyh mimics the built in spy but returns a handle which allows modifying the plot.
function h = spyh(A)
    [n,m] = size(A);
    [I,J] = find(A);

    if ~isempty(J)
        h = plot(J,I);
        h.LineStyle = 'none';
        h.Marker = '.';
        h.MarkerSize = 14;
    else
        h = [];
    end

    a = gca;
    xlim([0 m+1]);
    ylim([0 n+1]);
    axis square
    a.YDir = 'reverse';
end