{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Chapter4-33

# Chapter4-33 - (Moreon min/maxOperations sortOperation...

This preview shows pages 1–5. Sign up to view the full content.

Iteration Control Structure (More on) min / max  Operations sort  Operation And a new (unrelated, but sometimes useful) function  mod()

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Min/Max and Sort Operations MATLAB has functions to do these – min() , max() and sort() , but this is an exercise in algorithm development (logical sequence of steps to solve a problem). Let’s start with min (max is identical except for 1 simple change).
Min Operation Problem – Find the minimum value (and its position) in a row vector of an arbitrary number of numbers. To assist in visualization, let’s make a row vector of numbers [3 5 2 4] (except maybe show them vertically) 3 5 2 4 See if you can determine a technique (algorithm) to manually find the minimum value (and its position) in a list (row vector) of numbers (other than “I can see 2 in pos 3 by inspection.”).

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Min Operation You would (I assume) save the 1st number in position (index) 1 as the smallest. You would then scan the list starting with the 2nd number down until (or if) you found a smaller number than the 1st number If you found a small number than the 1 st , you would replace the 1 st (until then smallest) number with the one you found and replace (until then the smallest number) position with the position of the number you found.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}