Please help me with this error!

1 visualización (últimos 30 días)
April
April el 1 de Mayo de 2021
Comentada: April el 1 de Mayo de 2021
W = [1 4 3 3 9 7 5 10 5 8 6];
a=[1 2 4 2 1 1 1 3 3 4 2];
b=[2 4 6 5 5 4 3 6 4 5 3];
DG = sparse(a,b,W);
% tril returns the lower triangular part of the matrix.
UG = tril(DG + (DG'));
h = view(biograph(UG,[],'ShowArrows','off','ShowWeights','on'));
[dist,path,pred] = graphshortestpath(UG,1,6,'Directed',false);
set(h.Nodes(path),'Color',[1 0.4 0.4])
fowEdges = getedgesbynodeid(h,get(h.Nodes(path),'ID'));
revEdges = getedgesbynodeid(h,get(h.Nodes(fliplr(path)),'ID'));
edges = [fowEdges;revEdges];
set(edges,'LineColor',[1 0 0]);
set(edges,'LineWidth',1.5);
I got the error : Error using +
Matrix dimensions must agree.
Error in tesing (line 10)
UG = tril(DG + (DG'));
Thank you!

Respuesta aceptada

Walter Roberson
Walter Roberson el 1 de Mayo de 2021
W = [1 4 3 3 9 7 5 10 5 8 6];
a=[1 2 4 2 1 1 1 3 3 4 2];
b=[2 4 6 5 5 4 3 6 4 5 3];
mx = max(max(a),max(b));
DG = sparse(a,b,W,mx,mx);
% tril returns the lower triangular part of the matrix.
UG = tril(DG + (DG'));
h = view(biograph(UG,[],'ShowArrows','off','ShowWeights','on'));
[dist,path,pred] = graphshortestpath(UG,1,6,'Directed',false);
set(h.Nodes(path),'Color',[1 0.4 0.4])
fowEdges = getedgesbynodeid(h,get(h.Nodes(path),'ID'));
revEdges = getedgesbynodeid(h,get(h.Nodes(fliplr(path)),'ID'));
edges = [fowEdges;revEdges];
set(edges,'LineColor',[1 0 0]);
set(edges,'LineWidth',1.5);

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by