Help with matrix code
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
MK96
am 8 Jan. 2017
Kommentiert: Star Strider
am 8 Jan. 2017
I am attempting to create the adjacency matrix of a star tree: https://en.wikipedia.org/wiki/Star_(graph_theory)
I have the following for a 10 vertices graph:
AdjacencyMatrix = [0 1 1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0]; % sets the adjacency matrix
Is there a quicker way to create a matrix like this but of a larger scale e.g. 100x100?
0 Kommentare
Akzeptierte Antwort
Star Strider
am 8 Jan. 2017
One approach:
AdjacencyMatrix = zeros(100);
AdjacencyMatrix(2:size(AdjacencyMatrix,1), 1) = 1;
AdjacencyMatrix(1, 2:size(AdjacencyMatrix,2)) = 1;
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!