フィルターのクリア

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 Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by