matrix = rand(50,40);

% constants
[rows,cols] = size(matrix);

% partition the matrix
[GProws,GPcols,Wrows,Wcols] = PartitionTreeMatrixFiedler(matrix);

% extract row & column ordering data
ind_rows = ExtractData(GProws);
ind_cols = ExtractData(GPcols);

% the partitioning trees
[W_GProws,xy_GProws] = PartitionTreeDisplay(GProws);
[W_GPcols,xy_GPcols] = PartitionTreeDisplay(GPcols);

% rotate the row recursive partitioning tree
xy_GProws = ([0,1;-1,0]*xy_GProws')';
xy_GProws(:,2) = -xy_GProws(:,2);

% position and stretch the recursive partitioning trees
xy_GPcols(:,2) = 5*(xy_GPcols(:,2)-3)+rows;
xy_GProws(:,1) = 5*(xy_GProws(:,1)-3)+cols;

% display the partitioned, reordered matrix
close all
gplot(W_GProws,xy_GProws);
hold on;
gplot(W_GPcols,xy_GPcols);
imagesc(matrix(ind_rows,ind_cols)); axis equal; axis off; colormap(gray); set(gcf,'color','w');