Question

b, 15 marks] write a method that generates an m n matrix with its elements filled in with X or o randomly. The method takes in two integer parameters m and n and returns a 2D array of characters.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the Matlab code for you:

function board = fillBoard(rows, cols)

% Write a method that generates an mxn matrix with its element filled in

% with X or O randomly. The method takes in two integer parameters m and

% n and returns a 2D array of characters.

values = ['X' 'O'];

for i = 1 : rows

for j = 1 : cols

board(i, j) = values(randi(2));

end

end

end

And the output screenshot is:

604.24 MB <D < >し令동啦) 99% E , Wed 12 Apr 02:48 ANANDA KUMAR THUMMAPUDI a MATLAB R2013a MATLAB Window Help EDITOR APPS Search

Add a comment
Know the answer?
Add Answer to:
Write a method that generates an m times m matrix with its elements filled in with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT