Effacer les filtres
Effacer les filtres

Set dynamic random obstacles in GridWorld?

3 vues (au cours des 30 derniers jours)
Francesco Rizzo
Francesco Rizzo le 23 Mai 2022
How can i generate random obstacles in a gridworld environment?
GW.ObstacleStates = '[3,4]'; % this is a static thing, i want that the obstacle on every run change position in the grid

Réponses (1)

Manas
Manas le 3 Oct 2023
Hello Francesco Rizzo,
I understand that you want to write a MATLAB program that can generate a grid environment course with obstacles placed in random locations.
I’m assuming that you are referring a 2-Dimensional Map as GridWorld and obstacles as a block/flag on an individual cell.
Based on the above assumptions, either a cell array or a matrix can be used to represent the GridWorld, where each element in the matrix represents an individual cell in the GridWorld.
One way to mark an obstacle in the GridWorld is by storing binary data in the matrix, i.e ‘1’ represents an obstacle and ‘0’ represents a clear path.
To randomly generate the obstacles, you can either the use the “randi” function or the “randperm” function.
Here is a sample implementation to highlight the workflow:
grid = zeros(5, 5); % Create a 5x5 grid
numObstacles = randi([1, 5]); % Generate a random number of obstacles (1 to 5)
for i = 1:numObstacles
row = randi([1, 5]); % Randomly select a row
col = randi([1, 5]); % Randomly select a column
grid(row, col) = 1; % Assign obstacle at the randomly selected position
The above implementation is only intended to give you an idea on how to use MATLAB functionalities to solve the problem. Please feel free to modify it according to your requirements.
I’m adding documentation links to relevant MATLAB functionalities for your reference.
Hope this helps!

Catégories

En savoir plus sur Linear Algebra dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by