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...
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,...
Create one sql script file to complete the following. You cannot run separate SQL statements for...
Create one sql script file to complete the following. You cannot run separate SQL statements for the homework. You will also need to place a semicolon after each SQL statement, a requirement for SQL files containing multiple SQL statements Lesson 3 Write a query to display the current date. Label the column DATE. Display the last name of all employees who have an A and an E in their last name. For each employee, display the employee number, last_name, salary,...
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 =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT