Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.81 KB | None | 0 0
  1. % https://uk.mathworks.com/help/matlab/ref/digraph.html
  2.  
  3. row = 3;
  4. col = 5;
  5.  
  6. filename = strcat( int2str(row), 'x', int2str(col), '.csv' ); % examle: 3x5.csv
  7.  
  8. if exist(filename, 'file')  == 0 % Jeśli pliku nie ma, stwórz przykładową macierz
  9.     X = magic(col);               % macierz kwadratowa
  10.     M = reshape(X,col,[]) ;    % trzy wiersze
  11.     csvwrite(filename,M);
  12.  end
  13.  
  14. %  M = [
  15. %         1,3,1;  
  16. %         2,1,3;  
  17. %         2,8,3   % waga
  18. %         ];
  19.  
  20. M = csvread(filename)
  21.  
  22. Sx(1:size(M,1),1) = 0
  23.  
  24. for i=1:size(M,2)
  25.     for k=1:size(M,1)
  26.         Sx(i,1) = M(i,k)*i*k+Sx(i,1);
  27.     end
  28. end
  29.  
  30. Sx
  31.  
  32. s = M(1,:);  % Pierwszy wiersz macierzy M
  33. t = M(2,:);
  34. A = { M(1,:) , M(2,:), M(3,:) };
  35. weights  =  M(3,:);
  36.  
  37. tmp = size(M); % dimensions
  38. % Ilość liter alfabetu do wygeneroania. Dla każdego elementu macierzy
  39.  numbers=1:tmp(1)*tmp(2);        %musi być mnie niż 26 bo tyle mamy liter alfabetu
  40.  letters=char(numbers+64);
  41.  names = num2cell(letters);
  42.  
  43. % G = digraph(s,t,weights,names);
  44.  
  45. % plot(G,'Layout','force','EdgeLabel',G.Edges.Weight);
  46.  
  47.      % Construct the same digraph as in the previous example using two
  48.         % tables to specify edge and node properties.
  49.         s = [1 1 1 2 2 3 3 4 5 5 6 7]';
  50.         t = [2 4 8 3 7 4 6 5 6 8 7 8]';
  51.         weights = [10 10 1 10 1 10 1 1 12 12 12 12]';
  52.         names = {'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H'}';
  53. %         EdgeTable = table([s t],weights,'VariableNames',{'EndNodes' 'Weight'})
  54. %         NodeTable = table(names,'VariableNames',{'Name'})
  55. %         G = digraph(EdgeTable,NodeTable)
  56.  
  57. % plot(G,'Layout','force','EdgeLabel',G.Edges.Weight);
  58.  
  59. % clear A; N=1000; A=rand(N,N); tic, B=inv(A); toc, tic, C=A^-1; toc,
  60. % max(max(abs(B./C-1)))
  61. % clear A; N=100000; tic, A(N)=0; for(i=1:N) A(i)=i; end; toc, tic, for(i=1:N) A(i)=-i; end; toc,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement