A-star obstacles
3 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
Geoff
2012-3-22
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 个评论
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!