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

MATLAB is program Respond fast please a quiz Create a MATLAB script. Using nested for loops,...
MATLAB is program Respond fast please a quiz Create a MATLAB script. Using nested for loops, evaluate the multivariable function: z = sin ⁡ ( x ) cos ⁡ ( y ) for x between -4 and 4 in steps of 1 y between -2 and 2 in steps of 1 Display the matrix z Cut and paste the following into a word doc and submit to this question. Your script code Your input Your output
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...
Using Matlab, write code that carries out the following instructions: **Within your Live Script, create a...
Using Matlab, write code that carries out the following instructions: **Within your Live Script, create a matrix A by starting with eye(5) and performing the following sequence of elementary row-operations: first, replace (row4) with [(row4) + (row2) ⋅3], then, interchange rows 1 and 3 of the obtained matrix, and, finally, scale row5 of the matrix from the previous step by 6 to get the output matrix A. Display A. Note: To complete this part, you, should, first, create (and output)...
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,...
In a single Matlab script, plot a sine wave and cosine wave over 2 periods (0...
In a single Matlab script, plot a sine wave and cosine wave over 2 periods (0 to 4π). Checkpoints of the requirements: Generate your independent variables first; the step size should be no larger than 0.1 so that it has enough samples to get smooth lines. Plot the two waves on the same graph.   Specify the line color and styles: red dashed line for sine & blue solid line with dot markers for cosine. Include axis labels and a descriptive...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT