MATLAB: Different line styles in network graph

graphMATLABplotting

I wondered if there is any way to change the style of individual lines in a network graph, constructed with graph() or digraph(). When plotting, there is an option 'LineStyle', but it does not allow for customization for each each. For instance, suppose I want to change the lines between 1 and 2 to dotted lines, while keeping the lines between the nodes themselves solid.
h=figure;
M = ones(2);
G = digraph(abs(M_int));
edgecolors = [-1 1 1 1];
plot(G, 'Layout', 'circle', 'ArrowSize', 20, 'EdgeAlpha', 1, ...
'EdgeCData', edgecolors, 'LineWidth', 3, 'NodeLabel', {},...
'Marker', 'o', 'MarkerSize', 100, 'NodeColor', 'k');
nLabels = {'1', '2'};
text([-1 1]-0.1, [0 0]+0.01, nLabels, 'Color', 'w', 'FontSize', 40); % node labels
ax = gca;
map = [1, 0, 0
0, 0, 1];
colormap(map);
ax.Visible = 'off';
h.Color = [1 1 1];
set(ax, 'Units', 'Inches', 'Position', [0 0 8 4]);
set(h, 'Units', 'Inches', 'Position', [1 1 8 4]);
Reference: https://nl.mathworks.com/help/matlab/ref/matlab.graphics.chart.primitive.graphplot-properties.html

Best Answer

One easy way to do this is to highlight the edges you want to change.
g = graph(bucky);
h = plot(g);
highlight(h, 49, 51, 'LineStyle', ':', 'EdgeColor', 'r', 'LineWidth', 12)
The edge between nodes 49 and 51 in the buckyball graph is now wider than the others, red, and dotted.
Note that you don't need to change one node and/or edge at a time; you can specify a path if you want.
highlight(h, ... % highlight
shortestpath(g, 29, 32), ... % a shortest path from nodes 29 to 32
'EdgeColor', 'r', ... % with red lines
'LineWidth', 2, ... % that are wider than the others
'MarkerSize', 8, ... % and have larger
'NodeColor', 'c', ... % cyan
'Marker', 's', ); % squares as the markers