From: John on
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
And the reason you're not using the built-in min() function is.......
From: John on
"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
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
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.'