Not sure if anyone here is familiar with matlab programming. Im supposed to create a structured array (resembling a game board) that acts as a predator/prey simulator. The user needs to specify the size of the game board. Within the gameboard im supposed to represent a couple of different animals. Zebras, represented with a 'Z' should occupy 10% of the gameboard, giraffes represented with a 'G' occupy another 10%, hyenas represented with an 'H' occupy 5%, and there will be 1 lion represented with an 'L'. Unoccupied spaces will be represented with a hyphen.(adsbygoogle = window.adsbygoogle || []).push({});

this is what i've come up with so far. I tried making the board filled with hyphens, and then replacing them by specifying different animals for random locations within the board. There might be an easier way to do this using vectorization and not for loops. Im also confused about how I should make each animal occupy random locations that amount to a certain percent of the gameboard. How can I do this randomly without having the same locations within the array specified twice? Once agian, vectorization might offer an easier means to doing this, im just not sure how.

Any help you can offer will be greatly appreciated!!!

function board = makeBoard(rows,cols)

for rowIndex = 1:rows

for colIndex = 1:cols

board(rowIndex,colIndex).type = '-';

end

end

%creates a structured array with hyphens at each location

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Matlab Problem structured array

Loading...

Similar Threads - Matlab Problem structured | Date |
---|---|

Does anyone had this plotting problem with MATLAB? | Dec 23, 2017 |

Matlab map representation problems | Feb 11, 2017 |

Matlab Problem with Generating Barnsley Fern Fractal in MATLAB | Sep 21, 2016 |

Problem of plotting picture and video in Linux HPC | Dec 3, 2015 |

Matlab: Problem with structures | Sep 2, 2011 |

**Physics Forums - The Fusion of Science and Community**