Asked by faiza gul
on 2 Jan 2019

I have created random obstacles in MATLAB, (they are user acquired) now I am trying to make some obstacles randomly moving.

I Know that, in every iteration value of some obstacle be updated by adding some threshold valueto it.

But I am getting how to write up in code.

Kindly help me

Answer by darova
on 10 Sep 2019

Accepted Answer

After long 7 month of training and research i reached a success. Here is what i've achieved

clc,clear

px = 5*rand(10,1); % initial position

py = 5*rand(10,1);

plot(px,py,'.r')

axis([-1 1 -1 1]*20)

hold on

t = 360*rand(size(px)); % initial direction in degree

for i = 1:20 % number of iterations

dx = 0.5*cosd(t); % how fast we move

dy = 0.5*sind(t);

t = t + 90*(0.5-rand(size(px))); % change direction (-45:45) degree

plot([px px+dx]', [py py+dy]') % plot displacement

px = px + dx; % new position

py = py + dy;

h = plot(px,py,'.b'); % plot new position

pause(0.2) % wait

delete(h) % remove new position

% from graph

end

hold off

faiza gul
on 10 Sep 2019

Thats amazing and exceptional. truly good work

darova
on 10 Sep 2019

Thank you :)

Pravija Raj
on 19 Sep 2019

Many thanks for your response and really appreciate your work.

Thank you.

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 12 Comments

## Geoff Hayes (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/437929-making-moving-obstacles-in-an-matlab#comment_656207

## faiza gul (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/437929-making-moving-obstacles-in-an-matlab#comment_656247

## Geoff Hayes (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/437929-making-moving-obstacles-in-an-matlab#comment_656513

## faiza gul (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/437929-making-moving-obstacles-in-an-matlab#comment_656519

## Geoff Hayes (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/437929-making-moving-obstacles-in-an-matlab#comment_656626

## faiza gul (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/437929-making-moving-obstacles-in-an-matlab#comment_656633

## Geoff Hayes (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/437929-making-moving-obstacles-in-an-matlab#comment_656695

## faiza gul (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/437929-making-moving-obstacles-in-an-matlab#comment_656782

## Geoff Hayes (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/437929-making-moving-obstacles-in-an-matlab#comment_656847

## faiza gul (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/437929-making-moving-obstacles-in-an-matlab#comment_656884

## Pravija Raj (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/437929-making-moving-obstacles-in-an-matlab#comment_736658

## faiza gul (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/437929-making-moving-obstacles-in-an-matlab#comment_744420

Sign in to comment.