Thread Subject: Minimum Value

Subject: Minimum Value

From: Raju Gain

Date: 19 Aug, 2008 22:52:01

Message: 1 of 8

Hi,

I have a variable which is an array of all positive
numbers. I am trying to find the minimum value in the
varibale other than zero. Can anyone suggest how I can do
this? I was using the min() function before.

Thanks for your time.

Subject: Minimum Value

From: bogfrog

Date: 20 Aug, 2008 03:38:38

Message: 2 of 8

> Hi,
>
> I have a variable which is an array of all positive
> numbers. I am trying to find the minimum value in the
>
> varibale other than zero. Can anyone suggest how I
> can do
> this? I was using the min() function before.
>
> Thanks for your time.
>

min(my_array(find(my_array > 0)))

Subject: Minimum Value

From: Matt Fig

Date: 20 Aug, 2008 04:08:01

Message: 3 of 8

By, "All positive values" it seems you are including zero.
So your array has values >0? There are several ways to
tackle this, here's one that assumes you want to keep a intact:

a = [0 52 200 13 99 8 2 31 29 10 60 0]; % Data.

tmp = a;
tmp(tmp==0) = NaN; % Get rid of your zeros.
min(tmp) % The value you want.

Subject: Minimum Value

From: Walter Roberson

Date: 20 Aug, 2008 06:58:45

Message: 4 of 8

bogfrog wrote:

>> I have a variable which is an array of all positive
>> numbers. I am trying to find the minimum value in the
>> varibale other than zero.

> min(my_array(find(my_array > 0)))

The find() step is unnecessary

min(my_array(my_array > 0))

--
Q = quotation(rand);
if isempty(Q); error('Quotation server filesystem problems')
else sprintf('%s',Q), end

Subject: Minimum Value

From: Paul

Date: 20 Aug, 2008 07:43:02

Message: 5 of 8

"Raju Gain" <supernova5271@yahoo.com> wrote in message
<g8fiqh$1q0$1@fred.mathworks.com>...
> Hi,
>
> I have a variable which is an array of all positive
> numbers. I am trying to find the minimum value in the
> varibale other than zero. Can anyone suggest how I can do
> this? I was using the min() function before.
>
> Thanks for your time.
>

if x is your array:

minvalue = min(x((x~=0)))

Subject: Minimum Value

From: bogfrog

Date: 20 Aug, 2008 08:05:09

Message: 6 of 8

> The find() step is unnecessary
>
> min(my_array(my_array > 0))


Thanks for that. I thought the 0's in the output of a logical expression would cause an index error. But obviously not!

Subject: Minimum Value

From: David

Date: 20 Aug, 2008 09:58:02

Message: 7 of 8

"Raju Gain" <supernova5271@yahoo.com> wrote in message
<g8fiqh$1q0$1@fred.mathworks.com>...
> Hi,
>
> I have a variable which is an array of all positive
> numbers. I am trying to find the minimum value in the
> varibale other than zero. Can anyone suggest how I can
do
> this? I was using the min() function before.
>
> Thanks for your time.
>

maybe something like:

>> a=[0 1 2 3 4 5]

a =

     0 1 2 3 4 5

>> min(a(a>0))

ans =

     1

>>

Subject: Minimum Value

From: Titus

Date: 20 Aug, 2008 10:13:23

Message: 8 of 8


"bogfrog" <jmcgraw@rcn.com> schrieb im Newsbeitrag
news:15362310.1219219539684.JavaMail.jakarta@nitrogen.mathforum.org...
>> The find() step is unnecessary
>>
>> min(my_array(my_array > 0))
>
>
> Thanks for that. I thought the 0's in the output of a logical expression
> would cause an index error. But obviously not!

That is the reason why logicals were added (somewhere around MATLAB 6.0),
false/true is something different then 0/1:

>> A = [1 2 3];
>> A([true false true])
ans =
     1 3

>> A([1 0 1])
??? Subscript indices must either be real positive integers or logicals.

>> A(A~=2)
ans =
     1 3

This is called "logical indexing".

Titus


Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com