A-star obstacles

Hello, I'm trying to my a-star program working. I need to plot the path between 2 points while avoiding obstacles. I have already got the path part done, but I'm having some issues with the obstacles.
The user is selecting point one and two, as well as obstacles on a GUI grid.
So far I have c(c==o] = []; to remove the obstacles(o) from the the parent/child numbers(c)
this works with one obstacle as the o value is just one number so it simply deletes it, but for multiple obstacles, o has many numbers inside of it(array) so it just errors and says
" Error using == Matrix dimensions must agree."
I'm guessing this is because, the code above is trying to remove numbers which are in o from c, but they aren't even in c yet, so it can't do it.
How can I resolve this problem?

답변 (1개)

Geoff
Geoff 2012년 3월 22일

0 개 추천

The problem is you can only compare matrices with the same dimensions, or a matrix with a scalar. You want to compare a matrix with multiple scalars.
You could just loop through each obstacle:
for ob = o
c(c==ob) = [];
end
Edit: this does the same thing (didn't know about this function before). It ought to be more efficient.
c(ismember(c,o)) = [];

댓글 수: 2

marc buckle
marc buckle 2012년 3월 22일
Thanks for the answer, however this doesn't solve the problem.
http://i41.tinypic.com/dvlpn6.png
When I try this, the plot just goes of the screen and doesn't error :/
Geoff
Geoff 2012년 3월 22일
Well I can't vouch for the correctness of the rest of your algorithm, but I think I answered your question on how to fix the error message and remove multiple obstacles from your candidates.

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

카테고리

도움말 센터File Exchange에서 Language Fundamentals에 대해 자세히 알아보기

질문:

2012년 3월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by