help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: find minimum non-zero


From: Kai Torben Ohlhus
Subject: Re: find minimum non-zero
Date: Wed, 13 Nov 2019 00:31:46 +0900
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.1

On 11/12/19 8:45 AM, shivax via Help list for GNU Octave wrote:
> hi, look that:
> a=
>  1   0   0   8   7   0   0   2
>  0   0   0   0   0   0   0   0
>  2   0   0   6   0   0   1   0
> 
> i want find vector with minimun non-zero
> 
> 
> and: 1 (minimun non-zero in  rows n.1)
>         0 ( don't find minimum non-zero in  rows n.2)
>         2 (minimun non-zero  in  rows n.3)
> 
> it's possible to code it avoing loop?
> 

Does this work for your problem?

  a = [...
     1   0   0   8   7   0   0   2; ...
     0   0   0   0   0   0   0   0; ...
     2   0   0   6   0   0   1   0];

  a(a == 0) = inf;
  b = min (a, [], 2);
  b(isinf (b)) = 0

I think the answer for the third row should be "1", right?

HTH,
Kai



reply via email to

[Prev in Thread] Current Thread [Next in Thread]