my son has a project involving making a simulated roomba robot vacuum cleaner go around a generated room map, detect the obstacles, and then output a new room map with the obstacles in their (correct) detected places. the user inputs the desired rectangular room size, then the drawmap function generates a room on screen and takes random generated values from a 4x4 matrix to places "obstacles" in the displayed map. he has that part done and working correctly, but is having trouble coming up with code to 1) move the roomba (basically the index) vertically and horizontally through the "room," 2) detect the obstacles (depicted as lines or figures outlined by the * character on screen), and 3) mark the obstacles for display in the new room map. i would guess the detected/marked obstacles would be stored in a second 4x4 matrix that would then be used to display the obstacles in the new map. any suggestions? the drawmap function was new to him so he does not know how that works...
matlab code for simulated roomba to detect randomly generated obstacles
this is a fascinating project but offering much help with the code probably means you're going to need to go into more detail about your requirements and your current codebase.

my questions, offhand:
how large and what shape is the detection area for the roomba?
how exactly are the objects generated and what forms do they take?
is the simulated roomba allowed to pass through the obstacles?
how "stupid" do you want the roomba to be about things like the size and shape of the room and obstacles?
how do you want the roomba to move through the room? should it prioritize vertical paths over horizontal? when it finds an object, should it try to discover the entirety of the object or should it try to get back to the original path? what if there are regions that are theoretically unobstructed but which the roomba is too "large" to enter?
my thoughts on solutions:
decide on a plan for how the roomba should move in an unknown environment and when it encounters obstacles. for example, choose to move vertically until an object is found, then (assuming a collision should redirect the roomba) have the roomba follow the outline of the object clockwise until it reaches the original position again, at which time it should move to the other side of the object and continue scanning up and down.
have the detection logic work as follows: the roomba is in position (x,y) (assume there aren't already obstacles in detection range). first, it attempts to move to position (x+1,y). the program then verifies that no obstacles are inside range. if so, it attempts to move to (x+2,y). if there is an obstacle in detection range, the roomba's position again becomes (x,y) and the detected position of the obstacle is recorded.
rather than trying to reduce the size of the stored obstacles by storing them in a small matrix like that (which i assume contains the coordinates for two corners of a rectangle or a corner, length and height) let the detected obstacles appear in a matrix like they would on a map.
i've drawn out what i mean by 2 and 3 below:
move 1:
% room map
***********************************************
* *
* *
* ***** *
* * a * *
* ***** *
* *
* [] * % the roomba is two row from impacting a
* * % and is at position (x,y)
***********************************************
% search map
***********************************************
* *
* *
* *
* *
* *
* *
* [] * % the roomba knows nothing
* * 
***********************************************
move 2:
***********************************************
* *
* *
* ***** *
* * a * *
* ***** *
* [] *
* * % the roomba is one row from impacting a
* * % at position (x+1,y)
***********************************************
move 3:
% room map
***********************************************
* *
* *
* ***** *
* * a * *
* []*** *
* *
* * % the roomba impacts a
* * % at position (x+2,y)
***********************************************

***********************************************
* *
* *
* ***** *
* * a * *
* ***** *
* [] *
* * % the roombra is moved back to position (x+1,y)
* * 
***********************************************
% search map
***********************************************
* *
* *
* *
* *
* ** *
* [] *
* * % data about the impact is added
* * % to the output map
***********************************************
move 4:
***********************************************
* *
* *
* ***** *
* * a * *
* ***** *
* [] *
* * % the roombra is moved to position (x+1,y-2)
* * % to get around what it has seen of the obstacle
***********************************************