COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Find minimum value in array

• Follow

```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
```
 0

```And the reason you're not using the built-in min() function is.......
```
 0

```"John " <Nickg5859@gmail.com> wrote in message <hpe0c4\$fmn\$1@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
```
 0

```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.
```
 0

```On Apr 6, 2:19=A0pm, ImageAnalyst <imageanal...@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. =A0And inside that for loop is
> where you want the if statement, to compare if the current value is
> less than the current max value. =A0That'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.'
```
 0

4 Replies
622 Views

Similiar Articles:

7/26/2012 11:43:56 AM