Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Matlab LAB 2 Objective to expand our understanding of indexes for rows and columns of arrays. Again no Matlab built in functions are allowed to

Matlab LAB 2
Objective to expand our understanding of indexes for rows and columns of arrays. Again no Matlab built in functions are allowed to solve the requirements below except for the ones I give you in the assignment.
Write the program to cycle until the users chooses to stop. Read survey embedded in Course Doc for technique (while loop).
Part A:
Using a statement similar to the one below(item 3):
1. Have the user input the single value for the row/column size of a square array. Square arrays have the same number of rows and columns. (note: The array elements will still be in the form A(i,j)
2. Have the user input a number between 0 and 9.
3. Using a statement similar to b = uint16(rand(5,5)*9); % digits 0 to 9 integers ( see Random_a.m line 9 Matlab file)
4. Create a random square array. Note b is to be replaced by your array name. rand(5,5) is replaced by rand(?,?) where the ? are the same value, the value that the user input in item 1 above. Do not change the 9.
5. Write a for loop to find and count how many times the number (item 2 above) entered, occurs in the array you created in item 4 above. The answer can be 0. The size of the array varies so the number of random numbers varies. i.e. a 3x3 array has 9 values where a 6x6 array has 36 values which will increase the chance of some occurrences of the number.
6. Display the array you created
7. Use fprintf to show the number searched for and how many times it occurred.
Part B: (Note this part takes some thought so please get Part A working before you start this Part)
In this part you will be challenged to understand the indices for rows and columns using a square array.
1. Creata a random square array as you did in Part A. (items 3 and 4 above).
2. Compute the sum of the 2 diagonals.
a. Diagonal 1 is from the upper left corner to the lower right corner.
b. Diagonal 2 is from the upper right corner to the lower left corner.
3. Use fprintf to show the 2 sums.
NOTE for PART B You cannot simply write the individual array elements along the diagonals. That would get the right answer but not use programming to solve this algorithm. You need to take a small array 3x3 or 4x4 on paper, dont put numbers in the array but put the array elements names or reference in each square so that you can study the diagonal row and column indices. For each diagonal there is an equation relating the row index with the column index. The equations are different with Diagonal 1 a very simple relationship and diagonal 2 not complex but it requires some thought and study.
Also because there is a relationship between these indices you only need one for loop.
A suggestion: Think about this for loop driving the rows. Then the column index for the array elements would look similar to this: A(i, f(i)) for diagonal 1 f(i) is very simple. For Diagonal 2 it is a slightly more complex expression.

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_2

Step: 3

blur-text-image_3

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

Moving Objects Databases

Authors: Ralf Hartmut Güting, Markus Schneider

1st Edition

0120887991, 978-0120887996

More Books

Students also viewed these Databases questions

Question

How has the competition changed within the last three years?

Answered: 1 week ago

Question

What lessons can be learned from such cases?

Answered: 1 week ago