CAN SOMEONE HELP ME WITH THE PLOT?

1 次查看(过去 30 天)
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 个评论
darova
darova 2020-2-19
Can you make a drawing of the result you expect?
Rahul Bhaumik
Rahul Bhaumik 2020-2-20
Here is the path marked in bold, sorry I could not draw all the nodes hope you will understand.
Thanks a lot for helping out.

请先登录,再进行评论。

回答(1 个)

darova
darova 2020-2-20
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

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by