Re: Second minimum
- From: J <not@xxxxxxxxxxxxx>
- Date: Tue, 30 Aug 2005 13:22:06 -0400
thanks.
works perfectly
John D'Errico wrote:
>
>
> In article <ef127e7.-1@xxxxxxxxxxxxxxxx>, James
<not@xxxxxxxxxxxxx>
>
> wrote:
>
>> Hi,
>>
>> Does anyone know if there is an easy way in matlab to obtain
the
>> second minima along the length of a matrix.
>>
>> for example
>>
>> A = 0 0 0 1 0 0 2 3 0 0
>> 0 0 0 0 1 0 0 2 3 0
>> 0 0 0 0 0 1 0 0 2 0
>>
>> I would like to obtain the result
>>
>> t = 0 0 0 1 1 1 2 2 2 0
>>
>> thanks in advance
>> James
>
> You want to know the second smallest number in each column?
> from your example, it looks as if you want the second
> smallest distinct number in each column. This seems to
> run afoul of the case where a column has only 1 distinct
> value.
>
> The simplest solution would just use a loop and the function
> unique, working on each column individually. Is there a
> vectorized solution? Probably so.
>
>
> [B,tags] = sort(A);
> [junk,ind]=max([zeros(1,size(A,2));diff(B)~=0])
>
>
> ind =
>
> 1 1 1 3 3 3 3 2 2 1
>
> Ind is the index into the row of the sorted array which
> contains the second largest element in that column. If
> there was only 1 element, then ind is 1 for that column.
>
> Now use the tags array to back out where it came from
> in the unsorted array. You should get the drift now.
>
> HTH,
> John D'Errico
>
>
> --
> The best material model of a cat is another, or
> preferably the same, cat.
> A. Rosenblueth, Philosophy of Science, 1945
>
.
- References:
- Second minimum
- From: James
- Re: Second minimum
- From: John D'Errico
- Second minimum
- Prev by Date: Matlab Beginner fundamental issues
- Next by Date: Re: Processing an AVI file
- Previous by thread: Re: Second minimum
- Next by thread: s-function material
- Index(es):
Relevant Pages
|