Question

In: Computer Science

Create a single MatLab script named Problem3.m that, when run, does the following: -Defines a blank...

Create a single MatLab script named Problem3.m that, when run, does the following: -Defines a blank tic-tac-toe board: a 3-by-3 matrix called board, with blank spots represented by zeros. Echo the blank board to the command window. -Asks Player 1 for a row and a column, then puts a 1 in the given location. Echoes the new board. -Asks Player 2 for a row and a column, then puts a 2 in the given location. Echoes the new board.

Please write it so a person who is new at programming understands. Please note this is for MATLAB

Solutions

Expert Solution

Matlab code:

board = zeros(3,3)
i =0;
while(i<9)
if( mod(i,2) == 0 )
r = input('Player 1 please enter raw number\n');
c = input('Player 1 please enter column number\n');
else
r = input('Player 2 please enter raw number\n');
c = input('Player 2 please enter column number\n');
end
board(r,c) = 1;
board
i = i + 1;
end

Sample output

board =

0 0 0
0 0 0
0 0 0

Player 1 please enter raw number
1
Player 1 please enter column number
1

board =

1 0 0
0 0 0
0 0 0

Player 2 please enter raw number
1
Player 2 please enter column number
2

board =

1 1 0
0 0 0
0 0 0

Player 1 please enter raw number
1
Player 1 please enter column number
3

board =

1 1 1
0 0 0
0 0 0

Player 2 please enter raw number
2
Player 2 please enter column number
1

board =

1 1 1
1 0 0
0 0 0

Player 1 please enter raw number
2
Player 1 please enter column number
2

board =

1 1 1
1 1 0
0 0 0

Player 2 please enter raw number
2
Player 2 please enter column number
3

board =

1 1 1
1 1 1
0 0 0

Player 1 please enter raw number
3
Player 1 please enter column number
1

board =

1 1 1
1 1 1
1 0 0

Player 2 please enter raw number
3
Player 2 please enter column number
2

board =

1 1 1
1 1 1
1 1 0

Player 1 please enter raw number
3
Player 1 please enter column number
3

board =

1 1 1
1 1 1
1 1 1


Related Solutions

Create a bash script file named assessment-script-a that: 1. Accepts any number of file names on...
Create a bash script file named assessment-script-a that: 1. Accepts any number of file names on the command line 2. For each file name provided, delete any line that contains the string: qwe.rty When the changes are completed, the script should display the total number of files scanned, and the total number of files changed. Example Command: assessment-script-a file.a file.b file.c file.d file.e    Example Output: 5 files scanned, 3 files changed 3. Your script should include a series of...
Use MATLAB to create a script which solves for problem 5.9 in the book (5.11 in...
Use MATLAB to create a script which solves for problem 5.9 in the book (5.11 in the 4th edition). Given are the equations for the moment, as a function of x, starting from the leftmost side of the beam with x=0 and ending at the other end of the beam with x=12. This piecewise function together makes up the moment equation for the beam given. 0 ≤ ? ≤ 3 ?(?) = 265? − 5.56?3 , 3 < ? ≤...
(MATLAB) Write a script that would create a 3x5 matrix of random integers and write this...
(MATLAB) Write a script that would create a 3x5 matrix of random integers and write this new matrix to a file called “Assignment3_Question5.dat”.
Create a MATLAB script file to determine the given function is continuous or discontinuous at given...
Create a MATLAB script file to determine the given function is continuous or discontinuous at given interval (points).
UNIX/LINUX SCRIPT: Create a named directory and verify that the directory is there by listing all...
UNIX/LINUX SCRIPT: Create a named directory and verify that the directory is there by listing all its contents. Write a shell script to validate password strength. Here are a few assumptions for the password string.   Length – a minimum of 8 characters. • Contain alphabets , numbers , and @ # $ % & * symbols. • Include both the small and capital case letters. give a prompt of Y or N to try another password and displays an error...
(In Matlab) Create a base class named Point that has the properties for x and y...
(In Matlab) Create a base class named Point that has the properties for x and y coordinates. From this class derive a class named Circle having an additional property named radius. For this derived class, the x and y properties represent the center coordinates of a circle. The methods of the base class should consist of a constructor, an area function that returns 0, and a distance function that returns the distance between two points. The derived class should have...
Develop a matlab script file to calculate the practical single phase transformer parameters. The program should...
Develop a matlab script file to calculate the practical single phase transformer parameters. The program should ask the user to provide the following individually: S_rated V1_rated V2_rated With secondary shorted P1 V1 With primary open P2 I2 The program should calculate Req Xeq Zeq Gc Ym Bm Make sure your code will pronmpt a message like: “Enter the real power at the primary winding when the secondary winding is shorted, P1=). Do the same for all parameters S, V1_rated, V2_rated,...
Write a Matlab script-file probl1.m to execute the requested commands (as much as possible) in the...
Write a Matlab script-file probl1.m to execute the requested commands (as much as possible) in the exercises below. Increase N a number of times according to N = 4, 8, 16, 32, 64, 128, . . . (1) Determine for each N the (exact) error. (2) Determine for N ≥ 16 also the convergence ratio q(h/2). This script should be based on a function-file trap.m (trapezoidal integration) as follows: function [totarea] = trap(N) format long; a = 0; b =...
Matlab script that uses loops to create a multiplication table (matrix) where the user enters 'n'...
Matlab script that uses loops to create a multiplication table (matrix) where the user enters 'n' (nxn chart).
Matlab Code that does the following: Takes as input 3 frequencies. Create a signal that is...
Matlab Code that does the following: Takes as input 3 frequencies. Create a signal that is a mixture of the 3 signals. Create a bandpass filter that only selects the center frequency. Output the filtered signal which contains only the middle frequency. Plot in time and frequency domain the original signal and the filtered signal. Show the output for filter order 1 and 15. Upload a pdf of the image files. Each figure should have your name in the title...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT