From: John on 5 Apr 2010 20:48 I need to find the minimum value in an array and return an array [m n] where m is the smallest number and where n is the position in the array. I need to use recursion. This is what i have so far: function [m n] = recursiveMin(A) size = length(A); if isempty(A) m = []; n = []; elseif size == 1 m = A(1); n = 1; else A(1) = max; if %this is where im stuck end end Thanks for the help
From: ImageAnalyst on 5 Apr 2010 20:54 And the reason you're not using the built-in min() function is.......
From: John on 5 Apr 2010 21:41 "John " <Nickg5859(a)gmail.com> wrote in message <hpe0c4$fmn$1(a)fred.mathworks.com>... > I need to find the minimum value in an array and return an array [m n] where m is the smallest number and where n is the position in the array. I need to use recursion. This is what i have so far: > > function [m n] = recursiveMin(A) > > size = length(A); > if isempty(A) > m = []; > n = []; > elseif size == 1 > m = A(1); > n = 1; > else > A(1) = max; > if > %this is where im stuck > it a homework problem > end > > end > > Thanks for the help
From: ImageAnalyst on 5 Apr 2010 22:19 Well you don't want an "if" there (where you're stuck), you want a "for" loop, where you scan every element. And inside that for loop is where you want the if statement, to compare if the current value is less than the current max value. That's about all the hints I can give without outright doing it for you, which I'm not going to do.
From: TideMan on 5 Apr 2010 23:24 On Apr 6, 2:19 pm, ImageAnalyst <imageanal...(a)mailinator.com> wrote: > Well you don't want an "if" there (where you're stuck), you want a > "for" loop, where you scan every element. And inside that for loop is > where you want the if statement, to compare if the current value is > less than the current max value. That's about all the hints I can > give without outright doing it for you, which I'm not going to do. I don't understand why the OP is calling this "recursive". My understanding of recursion is when a function calls itself. OTOH, this could explain it: `When I use a word,' Humpty Dumpty said in rather a scornful tone, `it means just what I choose it to mean -- neither more nor less.'
|
Pages: 1 Prev: patch(isosurface(x)) Next: Voronoi and Delaunay vertices |