You need a function that's called BuildBoard() or something. Then in there call a function called PlaceShip() the required number of times.
function gameBoard = BuildBoard(rows, columns, numberOfShips)
gameBoard = false(rows, columns);
shipSizes = randi(maxShipLength, 1, numberOfShips)
for k = 1 : numberOfShips
gameBoard = PlaceShip(shipSizes(k));
Then in PlaceShip() you get a random location and direction. Then see if any of those locations is yet occupied by a prior ship. If none are then set those locations of gameBoard to true, otherwise try a different location until you succeed in placing it.