Adjacency matrix.I want to simply the code .
    3 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    mks
 el 13 de Ag. de 2023
  
    
    
    
    
    Comentada: mks
 el 14 de Ag. de 2023
            clc;
clear all;
n = 10;
C= zeros(n, n);
C(1,n)=1;
C(1,n-1)=1;
C(2,n)=1;
A = zeros(n, n);
for i = 1:n
    for j = 1:n
        if j==i+1 || j == i + 2
            A(i,j) = 1;
        else
            A(i, j) = 0;
        end
    end
end
B1=A+C
B=B1+B1';
G=graph(B);
plot(G)
0 comentarios
Respuesta aceptada
  Bruno Luong
      
      
 el 13 de Ag. de 2023
        
      Movida: Bruno Luong
      
      
 el 13 de Ag. de 2023
  
      n = 10;
x=accumarray([2 3 n-1 n]',1);
B = toeplitz(x,x);
G=graph(B);
plot(G)
Más respuestas (1)
  Walter Roberson
      
      
 el 13 de Ag. de 2023
        You can get a fair bit of the way with
B1 = diag(ones(n-1,1),1) + diag(ones(n-2,1),2);
You will still need to do the upper right corner, but that is not difficult (use two more diag calls)
0 comentarios
Ver también
Categorías
				Más información sobre Graph and Network Algorithms en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



