minMax - % be 'min' or 'max' to indicate whether the...

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

View Full Document Right Arrow Icon
% 9/21/2009 11:13 PM % Function Name: minMax % Inputs: % 1. double array - a vector of numbers % 2. char array - a string specifying min or max % % Outputs: % 1. double - min or max of input vector % 2. double - row of min or max % 3. double - column of min or max % % Function Description: % Write a function called minMax that takes in an array of numbers and a % selector for min or max and outputs the min or max and the row and % column of the FIRST appearance of that min or max. You should start % with the number at (1,1) and proceed downwards. Check every number in % that column before moving to the next column. The selector will either
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % be 'min' or 'max' to indicate whether the minimum or maximum should be % found. You may NOT use the min() or max() MATLAB functions for this % problem. % function [ ext row col ] = minMax(arr, cond) [ numr numc ] = size(arr); ext = arr(1,1); row = 1; col = 1; if strcmpi(cond, 'max') % the function is looking for the max in array for c = 1:numc for r = 1:numr if arr(r,c) > ext ext = arr(r,c); row = r; col = c; end end end elseif strcmpi(cond, 'min') % the function is looking for the min in array for c = 1:numc for r = 1:numr if arr(r,c) < ext ext = arr(r,c); row = r; col = c; end end end end end...
View Full Document

Ask a homework question - tutors are online