Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The first section should do the following: Clear the workspace and command window and close any figure windows Create a 1 0 x 1 0

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).
Target Locations
Application 1: Array Operations ENGR 1221
Designed to test skills with: array creation and operations; command-line input/output
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;
o 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: Remember the robot is actually located in a matrix, so the position (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 rob

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

Students also viewed these Databases questions