You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SaveAsciiGraph.m 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. function [edges] = SaveAsciiGraph(outFilePath, outFileName, graph, withSize)
  2. if nargin >= 3
  3. if nargin < 4
  4. withSize = 0;
  5. end
  6. if isdir(outFilePath) == 0
  7. mkdir(outFilePath);
  8. end
  9. outFullName = strcat(outFilePath,outFileName);
  10. numNodes = size(graph,1);
  11. numEdges = sum(sum(graph,1));
  12. edges = zeros(numEdges,2);
  13. e = 1;
  14. for i=1:numNodes
  15. for j=1:numNodes
  16. if graph(i,j) == 1
  17. edges(e,1) = i-1;
  18. edges(e,2) = j-1;
  19. e = e+1;
  20. end
  21. end
  22. end
  23. % save(strcat(outFullName,'_edges.txt'), 'edges', '-ascii');
  24. if withSize == 1
  25. SaveIntMatrixToFile(strcat(outFullName,'_edges.txt'), edges, numNodes);
  26. else
  27. SaveIntMatrixToFile(strcat(outFullName,'_edges.txt'), edges);
  28. end
  29. % save(strcat(outFullName,'_edges.mat'), 'edges');
  30. % save(strcat(outFullName,'_saveAsciiGraph.mat'));
  31. else
  32. fprintf('Invalid parameters. expecting: outFilePath, outFileName, graph\n');
  33. end