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
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
ADVERTISEMENT