Re: Second minimum



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



Relevant Pages

  • Re: Second minimum
    ... The simplest solution would just use a loop and the function ... then ind is 1 for that column. ... Now use the tags array to back out where it came from ... preferably the same, cat. ...
    (comp.soft-sys.matlab)
  • Re: Intresting interpolcation question
    ... John D'Errico wrote: ... >> of the array, ie nearest of .1 and .12. ... the 'nearest' solution would be easy to find. ... > same, cat. ...
    (comp.soft-sys.matlab)
  • Re: Intresting interpolcation question
    ... John D'Errico wrote: ... >> of the array, ie nearest of .1 and .12. ... the 'nearest' solution would be easy to find. ... > same, cat. ...
    (comp.soft-sys.matlab)
  • Re: Intresting interpolcation question
    ... > I want to set the new valueto the 'val' array at the location of ... > John D'Errico wrote: ... But you did not take the hint I gave you. ... The best material model of a cat is another, or preferably the same, cat. ...
    (comp.soft-sys.matlab)
  • Re: IF with nested AND
    ... Worked just fine for me with array entered. ... John C ... "Joco" wrote: ... which only works for the first cell in the ...
    (microsoft.public.excel.misc)