MATLAB: Setting EdgeColor in 2015B+ for graph.m

graph

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?

Best Answer

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.