Quiz8_Solution

# Quiz8_Solution - and return the appropriate outputs in the...

This preview shows page 1. Sign up to view the full content.

Quiz 8: Functions Name: ASE 201 Assume that your workspace has an array. You have no prior knowledge of the dimensions nor the values in the array. Write a function that will perform 2 tasks: 1. Calculate the maximum value in the array and its corresponding coordinates. These should be returned as outputs. 2. Finds the total number of values that are greater than 0. This should also be returned as an output. Once you have written the function, write that code that you would use to call the function
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: and return the appropriate outputs in the command window. Solution: %quiz8.m function [max,coord,num] = quiz8(Z) [n,m] = size(Z); num = 0; max = Z(1,1); for j = 1:n for k = 1:m if Z(j,k) >= max max = Z(j,k); coord = [j,k]; end if Z(j,k) > 0 num = num + 1; end end end end------------------------------------------[max,coord,num] = quiz8(Z)...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online