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