No BSD License  

Highlights from
CoCoMac

image thumbnail
from CoCoMac by James Allen
Download CoCoMac.org cortical connectivity data, model it as a network, and simulate epileptic sprea

pajeksave(matrix,labels,positions,file);
function pajeksave(matrix,labels,positions,file);
% pajeksave(matrix,labels,positions,file) - saves a matrix to a 
% .net file for Pajek-Software
% set labels to zero if none are available
% Author: Marcus Kaiser   Date: 15.08.02

n=length(matrix);

out=fopen(file,'w');
if out==-1,error('file could not be created'),end;

% is the matrix symmetric (i.e. undirected edges) ?
if (matrix == matrix') 
    symmetric = 1;
else
    symmetric = 0;
end;

% write vertices
fprintf(out,'*Vertices %d\n\r',n);
if ~isempty(labels)
    for i = 1:n
        if isempty(positions)
          fprintf(out,'%d "%s"\n\r',i,labels{i});
        else
          fprintf(out,'%d "%s" %f %f %f\n\r',i,labels{i},positions(i,1),positions(i,2),positions(i,3));
        end;
    end;
else
    for i = 1:n
        if isempty(positions)
          fprintf(out,'%d %d\n\r',i,i);
        else
          fprintf(out,'%d %d %f %f %f\n\r',i,i,positions(i,1),positions(i,2),positions(i,3));
        end;
    end;
end;    

% write edges or arcs
if (symmetric == 1) % write edges
    fprintf(out,'*Edges\n\r');
    for i = 1:n
        for j = 1:i
            if (matrix(i,j) ~= 0)
                fprintf(out,'%d %d %f\n\r', i, j, matrix(i,j));
            end;
        end; % for j
    end; % for i
else
    fprintf(out,'*Arcs\n\r');
    for i = 1:n
        for j = 1:n
            if (matrix(i,j) ~= 0)
                fprintf(out,'%d %d %f\n\r', i, j, matrix(i,j));
            end;
        end; % for j
    end; % for i
end; % if symmetric    

fclose(out);   

return

Contact us at files@mathworks.com