setEdgeColors (networkvisualizer)

index

setEdgeColors (networkvisualizer)

Set the edge colors of a networkvisualizer object.

Syntax

net = setEdgeColors(net, RGB)
net = setEdgeColors(net, values)
net = setEdgeColors(net, values, categories)
net = setEdgeColors(net, values, categories, classname)

Arguments

Description

Examples

Set the edge colors randomly to one of default colors

rng(1, 'twister'); % For reproducibility
% Generate a random network with 50 nodes and 100 edges
nNode = 8;
prepareRandomNetwork = @(n1, n2, numedges) logical(sparse(...
   randi([1 n1], numedges, 1), randi([1 n2], numedges, 1), 1, n1, n2));
W = prepareRandomNetwork(nNode, nNode, 100);
net = networkvisualizer(W);
net.setEdgeLineWidth(4);
% Set the node colors randomly to one of default colors
defaultcolors = net.getDefaultColors();
colors = defaultcolors(randi([1 3], length(net.Edges), 1), :);
net.setEdgeColors(colors);
% Plot the network
plot(net);

which produces:

Set the edge colors based on edge categories

size_values = randi([1 2], nNode, 1);
size_cats = {'small', 'big'};
net.addNodeClass(size_cats(size_values), 'NodeSize');
net.setNodeSizes({10, 20}, {'small', 'big'}, 'NodeSize');
% Create an edge class based on 'NodeSize' categories
net.createEdgeClass('EdgeCategory', 'NodeSize')
% Set the color of edges between small nodes as black
net = setEdgeColors(net, [0 0 0], 'small-small', 'EdgeCategory');
% Plot the network
plot(net);

which produces:

See Also

networkvisualizer, addNodeClass, addEdgeClass, createEdgeClass, setNodeSizes, setEdgeLineWidth, setEdgeLineStyle