CAN SOMEONE HELP ME WITH THE PLOT?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am new to MATLAB and could use some help with the issue I am facing, here is the code.
nodes = [(1:10); (10:10:100); (10:10:100)]';
segments = [(1:17); floor(1:0.5:9); ceil(2:0.5:10)]';
figure; plot(nodes(:,2), nodes(:,3),'k.');
hold on;
for s = 1:17
if (s <= 10) text(nodes(s,2),nodes(s,3),[' ' num2str(s)]); end
plot(nodes(segments(s,2:3)',2),nodes(segments(s,2:3)',3),'ko');
end
[d, p] = dijkstra(nodes, segments, 1, 10)
i = 1
for n = 2:length(p)
plot(nodes(p(n-1:n),2),nodes(p(n-1:n),3),'r-.','linewidth',2);
grid on
anim(i) = getframe;
i = i+1;
pause(2)
end
Result-
p =
1 2 4 6 8 10
Instead of intersecting points 3,5,7,9 can I make them follow a different path avoiding those points?
Please Help.
2 commentaires
Réponses (1)
darova
le 20 Fév 2020
My solution
x = 1 : 12;
y = x;
ind = [1 2 4 6 7 8 11];
plot(x,y,'.r')
hold on
for i = 1:length(ind)-1
x1 = x(ind(i));
x2 = x(ind(i+1));
y1 = y(ind(i));
y2 = y(ind(i+1));
if ind(i)+1 == ind(i+1)
plot([x1 x2],[y1 y2])
else
plot([x1 x1 x2],[y1 y2 y2])
end
end
hold off
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!