A-star obstacles

3 visualizzazioni (ultimi 30 giorni)
marc buckle
marc buckle il 21 Mar 2012
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?

Risposte (1)

Geoff
Geoff il 22 Mar 2012
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 Commenti
marc buckle
marc buckle il 22 Mar 2012
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 il 22 Mar 2012
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.

Accedi per commentare.

Categorie

Scopri di più su Language Fundamentals in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by