Question

This problem is of moderate complexity and illustrates how a flow chart can be useful in making a working code. Write a funct

EXECUTE [I, J] = myFind( M, key ) initialize outputs nRows = #of rows in M 1; pass nCols #of columns in M J Ccounter = 1 IS N

Your Function function [I, J ] = myFind( M, key ) 1 3%YOUR CODE HERE. Get the number of rows, cols in M. %initialize as empty

This problem is of moderate complexity and illustrates how a flow chart can be useful in making a working code. Write a function called myFind that accepts two inputs M and key, where M is an array of any size and key is a scalar. The function uses nested for-loops to search M for all locations of key. The function returns two equally sized column vectors I and J, containing the rows and columns, respectively, of every occurrence of key within array M. If key is not contained in M, the function returns empty arrays for and 3. Your algorithm with begin at (row, col) (1,1) and proceed down the first column, comparing each element with key. Upon reaching the end of the column, the process moves to the top of the next column, if any, and so on Example function calls >Ж - [10, 0, -5; 3.14, 10, 74.6; 10, 2, 7]; »[I,] myFind (M, 2) I = 3 2 [I,J] - myFind (M, 10) I= 1 2 1 2 >Mones(10); »[I,] myFind (M, 0) I = [1 Your function must not use the built-in fuction find. The flow chart is shown below. Note that the variable pass is used to make a new row in the output vectors each time key is found that the previous locations are not overwritten. You may submit your work as many times as you want Try to get 100%!
EXECUTE [I, J] = myFind( M, key ) initialize outputs nRows = #of rows in M 1; pass nCols #of columns in M J Ccounter = 1 IS NO Ccounter> nCols YES This block is automatically handled with the for-loop increment Ccounter Rcounter = 1 by 1 control statement for Rcounter 1:nRows YES IS NO Rcounter> nRows This block is automatically handled with the for-loop pOES M equal key control statement at location for Ccounter 1:nCols (Rcounter Ccounter) ? NO increment Rcounter by 1 YES END (pass, 1) Rcounter J(pass, 1) Ccounter; increment pass output I, J by 1
Your Function function [I, J ] = myFind( M, key ) 1 3%YOUR CODE HERE. Get the number of rows, cols in M. %initialize as empty array %intialize as empty array 7 8 YOUR CODE HERE, Finish the flow chart. 9 10 11 12 13 14 15 16 17 18 19 20 end 21 Code to call your function 1 M= [10, 0, -5; 3.14, 10, 74.6; 10, 2, 7]; 2 [I,] 3[I,3 4 M ones (10); 5[I,] myFind (M, 2) my Find (M, 10) myFind (M,0)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

function [I,J] = myFind(M,key)
[row cols] = size(M);
I = [];
J = [];
B = ones(cols,row);
for i = 1:row
for j = 1:cols
if(M(i,j)==key)
I = [I; i];
J = [J; j];

end
end
end
end

M = [10 0 -5;3.14,10, 74.6;10,2,7];
[I,J] = myFind(M,2)
[I,J] = myFind(M,10)



=================================================================
SEE OUTPUT
Your Code function [I, J] [row cols] I = ]; my FindCM,key size(M); I= 2 4 J ones(cols,row); B = for i = 1:row 6 for j = 1:col

Thanks, PLEASE COMMENT if there is any concern.

Add a comment
Know the answer?
Add Answer to:
This problem is of moderate complexity and illustrates how a flow chart can be useful in making a working code. Write...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The second problem, the one I'm asking about, is only making changes to the first problem, which ...

    The second problem, the one I'm asking about, is only making changes to the first problem, which I have included the correct code for. Thank you!! een be modeled by diding the plate io adiscrese grid of cels and sulting the change in tenspentureof ell over 90 2.2 3) dared es dlebel css (saggestion:use5 both ves w fint, ut increme this 1o 20asee you get yeur pragranı warking. Your progrars shcald do the Sllasing lain the cs alus of the...

  • cope the code please thanks Write a MATLAB code to obtain the following. Keep your code...

    cope the code please thanks Write a MATLAB code to obtain the following. Keep your code commented whenever required. Copy your source code and command widow outcomes and screen shots of any plots in your solution. Generate a matrix "A" as follow. A= 16 6 8 2 10 18 12 14 4 I. II. Divide the matrix A by 2 and store the result in a matrix B. Combine matrices A & B to obtain the following matrix C. Also...

  • 6. From the following flow-chart, write the java code. false a<100 print Done true print Bad...

    6. From the following flow-chart, write the java code. false a<100 print Done true print Bad a++ 7. Given an array int[] myarray = {2, 4, 6, 8, 9, 7, 5, 3, 1, 0} Create a trace table for variables involved in the following code int s = 10; for (int i = 3; i <7; i++) S = S + myarray[i]; What is the final value of s? 8. Given an ArrayList object mywords of the content Avengers Endgame...

  • How can I write this code (posted below) using vectors instead of arrays? This is the...

    How can I write this code (posted below) using vectors instead of arrays? This is the task I have and the code below is for Task 1.3: Generate twenty random permutations of the number 0, 1, 2, ..., 9 using of the algorithms you designed for Task 1.3. Store these permutations into a vector and print them to the screen with the additional information of unchanged positions and number of calls torand(). Calculate the total numbers of unchanged positions. Compare...

  • Please solve only if you know how to do it. Write the code using C++ (not...

    Please solve only if you know how to do it. Write the code using C++ (not Python or Java). Show and explain everything neatly. COMMENTS (7.5% of programming assignment grade): Your program should have at least ten (10) different detailed comments explaining the different parts of your program. Each individual comment should be, at a minimum, a sentence explaining a particular part of your code. You should make each comment as detailed as necessary to fully explain your code. You...

  • I need help fixing this code and adding a loop please. Here is the original problem: #include <iostream> using namespace std; //function to print seating chart void printSeatingChart(int **cha...

    I need help fixing this code and adding a loop please. Here is the original problem: #include <iostream> using namespace std; //function to print seating chart void printSeatingChart(int **chart) {    int i, j;    cout << "\nROW\t";    for (i = 1; i <= 10; i++)    {        cout << i << "\t";    }    cout << "\n-----------------------------------------------------------------------------------\n";    for (i = 8; i >= 0; i--)    {        cout << "\n" << i + 1 << "\t";        for (j = 0; j < 10; j++)       ...

  • Hi there I need help coming up with the C code for this problem. At the...

    Hi there I need help coming up with the C code for this problem. At the beginning of the program and before each function use comments to explain what the function does. Do not use global variables 1. The Pascal triangle can be used to compute the coefficients of the terms in the expansion of atb In a Pascal triangle, each element is the sum of the element directly above it and the element to the left of the element...

  • Please do in C please. Edit sliding.c. Comments on code would be nice. Thank you. Here is main.c #include "sliding.h" #include <malloc.h> #include <stdlib.h> //Prints grid in row...

    Please do in C please. Edit sliding.c. Comments on code would be nice. Thank you. Here is main.c #include "sliding.h" #include <malloc.h> #include <stdlib.h> //Prints grid in row major order. Tries to ensure even spacing. void print_grid(int * my_array, int rows, int cols){ int i,j; for(i=0; i<rows; i++){ for(j=0; j<cols; j++){ if(my_array[i*cols + j]!=-1){ printf(" %d ", my_array[i*cols + j]); } else{ printf("%d ", my_array[i*cols + j]); } } printf("\n"); } } int main(int argc, char *argv[]) { int seed,rows,cols;...

  • Help due in a few hours I need to clean this up can you help me clean up this code to accomplish the same task but with fewer lines/ more elegantly. Thank you! My code for the function is below: int...

    Help due in a few hours I need to clean this up can you help me clean up this code to accomplish the same task but with fewer lines/ more elegantly. Thank you! My code for the function is below: int is_valid_board(int board[9][9]) { int array[10]; int array_box[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; int i, j, k, x, y; //rows=i, columns =j for (i=0; i<9; i++) { //Reset test array for (x = 0; x...

  • This is an assignment for my algorithm class which I have written the code partially and...

    This is an assignment for my algorithm class which I have written the code partially and only need to complete it by adding a time function that calculates the average running time. We could use any programming language we want so I am using C++. I am including the instruction and my partial code below. Thank you! Implement linearSearch(a,key) and binarySearch( a,key)functions. Part A.In this part we will calculate theaverage-case running time of each function.1.Request the user to enter a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT