Thread Subject: How to find the index of approximately zero values in a matrix

Subject: How to find the index of approximately zero values in a matrix

From: Naomi Onodera

Date: 28 May, 2009 20:38:01

Message: 1 of 7

Hello,

For exemple, I have a matrix like: A=[4;3;2;1;0.0001;-1;-2;-3] and I would like to know how find autommatically the index of the number close to zero, or when the segment cross the x axis
I tried t=find(A==0), but my values are approximately zero and not exactly zero...
Somebody can help me, please?
Thank you
Naomi

Subject: How to find the index of approximately zero values in a matrix

From: juliette Salexa

Date: 28 May, 2009 20:44:02

Message: 2 of 7

"Naomi Onodera" <a.naomi@usp.br> wrote in message <gvmsn9$am2$1@fred.mathworks.com>...
> Hello,
>
> For exemple, I have a matrix like: A=[4;3;2;1;0.0001;-1;-2;-3] and I would like to know how find autommatically the index of the number close to zero, or when the segment cross the x axis
> I tried t=find(A==0), but my values are approximately zero and not exactly zero...
> Somebody can help me, please?
> Thank you
> Naomi

How about find(abs(A)<10^-3) ?? This gives the index 5
Please private message me if you find a better solution! I'm interested myself !

Subject: How to find the index of approximately zero values in a matrix

From: Matt

Date: 28 May, 2009 20:44:02

Message: 3 of 7

"Naomi Onodera" <a.naomi@usp.br> wrote in message <gvmsn9$am2$1@fred.mathworks.com>...
> Hello,
>
> For exemple, I have a matrix like: A=[4;3;2;1;0.0001;-1;-2;-3] and I would like to know how find autommatically the index of the number close to zero, or when the segment cross the x axis
> I tried t=find(A==0), but my values are approximately zero and not exactly zero...
> Somebody can help me, please?

You need a criterion for deciding what is "close to zero". For example, you could do

Tolerance=0.001;
t=find(abs(A)<Tolerance)

However, selecting an appropriate tolerance value is a situation-specific task.

Subject: How to find the index of approximately zero values in a matrix

From: juliette Salexa

Date: 28 May, 2009 20:49:01

Message: 4 of 7

"Naomi Onodera" <a.naomi@usp.br> wrote in message <gvmsn9$am2$1@fred.mathworks.com>...
> Hello,
>
> For exemple, I have a matrix like: A=[4;3;2;1;0.0001;-1;-2;-3] and I would like to know how find autommatically the index of the number close to zero, or when the segment cross the x axis
> I tried t=find(A==0), but my values are approximately zero and not exactly zero...
> Somebody can help me, please?
> Thank you
> Naomi

How about find(abs(A)<10^-3) ?? This give me the index "5"

Let me know if you find anything better though !! I'm also interested!

Subject: How to find the index of approximately zero values in a matrix

From: someone

Date: 28 May, 2009 21:33:01

Message: 5 of 7

"juliette Salexa" <n_dattani@hotmail.com> wrote in message <gvmtbt$mmo$1@fred.mathworks.com>...
> "Naomi Onodera" <a.naomi@usp.br> wrote in message <gvmsn9$am2$1@fred.mathworks.com>...
> > Hello,
> >
> > For exemple, I have a matrix like: A=[4;3;2;1;0.0001;-1;-2;-3] and I would like to know how find autommatically the index of the number close to zero, or when the segment cross the x axis
> > I tried t=find(A==0), but my values are approximately zero and not exactly zero...
> > Somebody can help me, please?
> > Thank you
> > Naomi
>
> How about find(abs(A)<10^-3) ?? This give me the index "5"
>
> Let me know if you find anything better though !! I'm also interested!

doc diff
doc sign

% If you just want the "zero-crossings" you could use something like:

diff(sign(A))

% But this may not help you much to find "near zero" places.
% The other suggestions are probably better in that case.
% Just a thought...

Subject: How to find the index of approximately zero values in a matrix

From: TideMan

Date: 28 May, 2009 21:36:39

Message: 6 of 7

On May 29, 8:38 am, "Naomi Onodera" <a.na...@usp.br> wrote:
> Hello,
>
> For exemple, I have a matrix like: A=[4;3;2;1;0.0001;-1;-2;-3] and I would like to know how find autommatically the index of the number close to zero, or when the segment cross the x axis
> I tried t=find(A==0), but my values are approximately zero and not exactly zero...
> Somebody can help me, please?
> Thank you
> Naomi

Here's a way that avoids having to set a tolerance:
indx=round(interp1(A,[1:length(A)]',0))

Of course, for this to work, A must be monotonic, as your A is.

Subject: How to find the index of approximately zero values in a matrix

From: Bruno Luong

Date: 29 May, 2009 19:39:02

Message: 7 of 7

TideMan <mulgor@gmail.com> wrote in message <6e3c30ed-d546-48b0-acfd-dbbaf28672aa@j18g2000prm.googlegroups.com>...
> On May 29, 8:38?am, "Naomi Onodera" <a.na...@usp.br> wrote:
> > Hello,
> >
> > For exemple, I have a matrix like: A=[4;3;2;1;0.0001;-1;-2;-3] and I would like to know how find autommatically the index of the number close to zero, or when the segment cross the x axis
> > I tried t=find(A==0), but my values are approximately zero and not exactly zero...
> > Somebody can help me, please?
> > Thank you
> > Naomi

simply
[dummy idx0] = min(abs(A))

No tolerance selection or monotonic requirement.

Bruno

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

Contact us at files@mathworks.com