# CAN SOMEONE HELP ME WITH THE PLOT?

1 view (last 30 days)
Rahul Bhaumik on 19 Feb 2020
Commented: Rahul Bhaumik on 22 Feb 2020
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?

darova on 19 Feb 2020
Can you make a drawing of the result you expect?
Rahul Bhaumik on 20 Feb 2020
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.

darova on 20 Feb 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

#### 1 Comment

Rahul Bhaumik on 22 Feb 2020
Thanks a lot. You are a life saviour.