# minStruct - % string. The string specifies the name of a...

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

Sheet1 Page 1 %========================================================================== % Problem 3. Sorting Structures %-------------------------------------------------------------------------- % % In homework 4, you implemented an algorithm to sort a vector. % You will now implement the same algorithm to sort a structure array based % on one of its fields. To do this, please complete parts A and B below. % In part A, you will write an alternative function to the min() function % to work on structures. You will use your function from part A to write % the sorting function in part B. %========================================================================== % Problem 3, part A. Finding a minimum structure %-------------------------------------------------------------------------- % % Problem Statment: % % Write a function named minStruct that takes in a structure array and a

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % string. The string specifies the name of a field in the structure % array of which you are to find the structure with the minimum value for % this field. You may assume that the given field will only contain % numeric, scalar values. Your function should return first the % structure having the minimum value for the specified field and second % the index of the returned structure. function [ans, loc] = minStruct(A,str) [r c] = size(A) vec = x = 1 y = 1 while x &lt;= r &amp;&amp; y &lt;= c vec(x,y) = A(x,y).(str) if x == r x = 1 y = y + 1 else y = y x = x + 1 end end if r &gt; 1 [v c1] = min(min(vec)) m = n = for b = 0:(r-1) n = vec(c1 + (c * b)) m = [m n] end [v, r1] = min(m) ans = A(r1,c1) loc = [r1 c1] else Sheet1 Page 2 [v c1] = min(vec) ans = A(1,c1) loc = c1 end...
View Full Document

## This note was uploaded on 07/06/2009 for the course CS 1371 taught by Professor Stallworth during the Fall '08 term at Georgia Institute of Technology.

### Page1 / 2

minStruct - % string. The string specifies the name of a...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online