function plot_envelope( A, envelope, row_label, col_label, title_str );
%
% PLOT_ENVELOPE  Plot the envelope of a binary matrix, A.
%
% row_label is the label for the rows, col_label is the label for the columns, 
% and title_str is the title string. 
% 
% plot_envelope( A, envelope, row_label, col_label, title_str );

% Copyright © Regents of the University of Minnesota. All rights reserved.

% Handle missing labels and title
if nargin < 5
    title_str = 'Support Envelope';
end;
if nargin < 4
    col_label = '\bf n \rm( min items)';
end;
if nargin < 3 
    row_label = '\bf m \rm(min transactions)';
end;

% The matrix is sorted so that the rows with the highest 
% column weight are at the top of the plot and the columns
% with the highest row weight are at the left.

block = A( envelope.row_indices, envelope.col_indices );
row_sum = sum( abs( block ), 2 );
[ sort_values_rows sort_indices_rows ] = sort( -row_sum );

col_sum = sum( abs( block ), 1 );
[ sort_values_cols sort_indices_cols ] = sort( -col_sum );

block = block( sort_indices_rows, sort_indices_cols );

% Plot the figure
figure; imagesc( block );
set( gcf, 'color', 'white' );
set( gca, 'fontsize', 16 );
ylabel( row_label, 'fontsize', 14 );
xlabel( col_label, 'fontsize', 14 );
title( title_str, 'fontsize', 14 );
grid;