function varargout=plot_network(varargin)
%PLOT_NETWORK Plot network structure.
% [A]=PLOT_NETWORK(NAME,NUMBER) is a script that plots structure number
% NUMBER saved in a NAME.MAT file in current working directory (for
% details see help CREATE_NETWORK).
%
% Matrix A is a incidence matrix, that function GPLOT uses for
% plotting.
%
% If NUMBER is not specified PLOT_NETWORK will plot STRUCTURE number 1.
%
% See also CREATE_NETWORK, CREATE_RAND_NETWORK.
% References:
% [1] T. E. Cormen et al., "Introduction to Algorithms",
% WNT, Warsaw 2000, page 527.
% Copyright 2003-2004 Przemyslaw Pawelczak
% E-mail: przemyslaw_pawelczak@idg.com.pl
% Wroclaw University of Technology, Poland
% $Revision: 1.0 $ $Date: 2004/02/01 11:44:36 $
%If no NUMBER specified then it will be first
if nargin==1
varargin{2}=1;
end
%Exeption handling
message=nargchk(1,2,nargin);
if ~isempty(message)
error('MATLAB:PLOT_NETWORK:NumberOfInputArguments',message);
end
if ~isstr(varargin{1})
error('MATLAB:PLOT_NETWORK:ArgumentType','Argument must be string.');
end
if find(isnan(varargin{2})==1)
error('MATLAB:PLOT_NETWORK:ArgumentType','Argument must be number.');
end
%Change string into number (for number of nodes)
if isstr(varargin{2})==1
varargin{2}=str2num(varargin{2});
end
%List all '*.mat' files in current working directory
%Change directory to MATLABROOT\networks - catalog must exist
cd([matlabroot,['\work\networks']]);
directory=what;
directory=struct2cell(directory);
directory=cellstr(directory{3});
if find(strcmp(directory,[varargin{2},'.mat'])==1)
error('MATLAB:PLOT_NETWORK:BadFileName','No such file name.');
end
%Loads file
load(varargin{1});
%Check how long is the current structure
structure_dimension=cellfun('ndims',structure);
struc_len=length(structure_dimension(:,:,1));
%Make incidence matrix
for k=1:struc_len
if ~isempty(structure{k,1,varargin{2}})
%Make incidence
for node=1:length(structure{k,1,varargin{2}})
incidence_matrix(k,structure{k,1,varargin{2}}(node))=1;
end
end
end
incidence_matrix_length=length(incidence_matrix);
%Create coordinates matrix - procedure 1
%Make coordinates where all nodes are in put in square
coordinates=zeros(incidence_matrix_length,2);
x=1/incidence_matrix_length;
for i=1:round(incidence_matrix_length/2)+1
coordinates(i,1)=x;
coordinates(i,2)=0.1;
x=x+1/incidence_matrix_length;
end
x=1/incidence_matrix_length;
for i=round(incidence_matrix_length/2)+1:incidence_matrix_length
coordinates(i,1)=x;
coordinates(i,2)=0.2;
x=x+1/incidence_matrix_length;
end
%Create coordinates matrix - procedure 2
%Make coordinates randomly
%for i=1:incidence_matrix_length
% coordinates(i,1)=rand;
% coordinates(i,2)=rand;
%end
%Graph plotting procedure
gplot(incidence_matrix,coordinates,'o-'), drawnow, axis off;
%Name all nodes with their numbers
for i=1:incidence_matrix_length
text(coordinates(i,1),coordinates(i,2),int2str(i));
drawnow;
end
varargout{1}=incidence_matrix;