CAN SOMEONE HELP ME WITH THE PLOT?

조회 수: 1 (최근 30일)
Rahul Bhaumik
Rahul Bhaumik 2020년 2월 19일
댓글: Rahul Bhaumik 2020년 2월 22일
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
  댓글 수: 1
Rahul Bhaumik
Rahul Bhaumik 2020년 2월 22일
Thanks a lot. You are a life saviour.

댓글을 달려면 로그인하십시오.

카테고리

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