Constructing a Maze with vectors

17 ビュー (過去 30 日間)
slowlearner
slowlearner 2020 年 9 月 10 日
コメント済み: John D'Errico 2020 年 9 月 12 日
first off I might have bin looking in the wrong places so if you have something i can deep dive in to i'd appriciate it!
To the problem: I have a maze i created that looks like the picture
i simply set the the values as follow:
%% this is the blue
x = [20 100 100 20];
y = [80 80 100 100];
%% this is the red
x1 = [65 65 100 100];
y2 = [60 20 20 80];
%% this is the yellow
x2 = [0 0 100 20 20];
y2 = [100 0 0 0 60];
%i then just use simple plotting method
plot(x,y)
hold on
plot(x1,y1)
plot(x2,y2)
axis([-20 120 -20 120])
Now this works fine and I can see that it is a maze and sure I could make it more intricate, however when I then tried to combine every x in to one big X in to a single vector it became like this picture
it seems that the end of vector x,y became coupled with the start of x1,y1 and the end of that vector with the start of x2,y2.
I couldn't really find any rules on this... was thinking if maby addning the conecting vectors to another plot and making them white but that's to.... sad? or if maby LineStyle, 'none' could be applied in anyway?
appriciate the input.

採用された回答

John D'Errico
John D'Errico 2020 年 9 月 10 日
Insert NaNs between eack block of lines.
X = [x,nan,x1,nan,x2];
Y = [y,nan,y1,nan,y2];
Now the various sets of line segments will not be connected by spurious lines.
  2 件のコメント
slowlearner
slowlearner 2020 年 9 月 11 日
編集済み: slowlearner 2020 年 9 月 12 日
king! thanks man didnt really know NaNs cNould be used a vector like that.
John D'Errico
John D'Errico 2020 年 9 月 12 日
Yes, it is one of those tricks you just need to know to solve this problem, but would not be at all obvious. NaNs are something you normally want to avoid. I'm happy to be of help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLabyrinth problems についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by