Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE CODE IN MATLAB: Structuring the Script File Since we have not yet covered loops or branching, you will enable repetition of the move operation

PLEASE CODE IN MATLAB: Structuring the Script File
Since we have not yet covered loops or branching, you will enable repetition of the move operation by dividing the script into 3 sections: initialization, movement, and reporting.
You can either create a new MATLAB script (.m) file or use the livescript template provided on Carmen. Ensure you save it with a name that indicates the assignment and your name (for example, Application3_Smith.m). To divide the script into sections, use a double-percent sign (%%). If you are creating your own script file, please see the template as a reference.
Initialization Section
The first section should do the following:
Clear the workspace and command window and close any figure windows
Create a 10x10 grid matrix of all zeros (this is the matrix that your robot will occupy)
Initialize the robots coordinates to be near the center [can be (5,5) or (6,6)] of the grid matrix by
setting that element of the grid matrix to 1
Create a second 10x10 matrix to represent the targets; initialize to all zeros as well
Using the input() function, prompt the user for the number of targets (should be between 1
and 100).
Randomly choose that number of elements of the target matrix and set them to 1. This line will accomplish that (assuming that your target matrix is called target and that the number of targets entered by the user is num_targets you may use whatever variable names you like):
targets(randi(100,[num_targets,1]))=1;
NOTE:this will not necessarily give unique target positions,so there is a chance that the number of targets placed in the matrix will be less than the number entered by the user (this is okay)
Display the robots location using the provided show_image function.
Set the title of the figure window so that it indicates the robots position. (You can do this using
string concatenation with the + operator)
3. Movement Section
The second section should do the following:
Prompt the user for how far to move the robot in the columns and rows
o NOTE:Remembertherobotisactuallylocatedinamatrix,sotheposition(1,1)is located
near the TOP left when graphed, not the BOTTOM left (what we typically imagine as the origin). What we typically think of as movement in the x direction is actually movement between columns and movement in the y direction is actually movement between rows
Update the robots position
Update the grid matrix set the element for the previous position to 0, and the new position to 1
Display the robots position just as in the initialization section (including title with correct robot
position location)
Determine if there is a target at the robots new coordinates. To accomplish this, perform an element-wise multiplication of the grid matrix by the target matrix, and take the sum of all elements. The result will be 0 if there is not a target at the robots location, or 1 if there is.
Set the element of the target matrix corresponding to the robots position equal to 0.(That is,
once a target is found, remove it from the target matrix.)
Print to the command line (using either disp or fprintf) a message [indicating whether a
target was found. Since we have not yet covered if statements, the easy way to do this is to select one of two messages from an array using indexing. (See the example message array in the script template above.)
Update the number of moves and number of targets found the former always increases by 1, while the latter increases by 1 only if a target is found.
4. Reporting Section
The third section should do the following:
Print to the command window a message indicating how many targets were found and how many moves were made
Print to the command window how many targets remain you can determine this by summing the entire target matrix
Display the targets using show_image.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions

Question

Different formulas for mathematical core areas.

Answered: 1 week ago

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago