Setting EdgeColor in 2015B+ for graph.m

조회 수: 4 (최근 30일)
Matlab2010
Matlab2010 2016년 3월 11일
댓글: Steven Lord 2016년 3월 11일
In 2015B graph.m is introduced graph.m.
A = ones(4) - diag([1 1 1 1]);
G = graph(A);
plot(G);
h=get(gca, 'Children');
%set(h, 'EdgeColor', 'red'); % I could do this but it sets all the edges red.
%set(h, 'EdgeColor', new_cols(i,1)); %I would like to be able to set each edge indivdualy.
How do I set individual edge colors?

채택된 답변

Mike Garrity
Mike Garrity 2016년 3월 11일
편집: Mike Garrity 2016년 3월 11일
It wants an array with 3 columns, and one row for each edge. The columns are the red, green, and blue components of the color for the edge which corresponds to the row.
The colormap functions return arrays of this type, so we can do things like this:
A = ones(4) - diag([1 1 1 1]);
G = graph(A);
h = plot(G);
h.EdgeColor = lines(G.numedges);
But you could create the array some other way.
  댓글 수: 1
Steven Lord
Steven Lord 2016년 3월 11일
In addition to what Mike said, if you want to make one particular edge or a few edges stand out rather than changing the color of every edge, take a look at the HIGHLIGHT function.
% Create the complete graph on 4 nodes (no self loops)
A = ones(4) - eye(4);
G = graph(A);
% Plot it with red edges of width 2
h = plot(G, 'EdgeColor', 'r', 'LineWidth', 2);
% Highlight the edge (2, 3) in black and make it width 5
highlight(h, 2, 3, 'EdgeColor', 'k', 'LineWidth', 5)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by