Thread Subject: Rounding to nearest data point.

Subject: Rounding to nearest data point.

From: jmeccles Eccles

Date: 11 Mar, 2010 13:55:21

Message: 1 of 3

I have a column of data points, and my function is taking in a completely separate number from these points. I want to be able to round this number to the nearest point from my column of data points.

Any help is greatly appreciated.

Thanks in advance.

Subject: Rounding to nearest data point.

From: Adam A

Date: 11 Mar, 2010 14:56:21

Message: 2 of 3

"jmeccles Eccles" <jared.eccles@hotmail.com> wrote in message <hnaso9$fdo$1@fred.mathworks.com>...
> I have a column of data points, and my function is taking in a completely separate number from these points. I want to be able to round this number to the nearest point from my column of data points.
>
> Any help is greatly appreciated.
>
> Thanks in advance.

How about something like the following:

index = find( abs(data(:)-value)==min(abs(data(:)-value)) ,1,'first');
result = data(index)

...where <data> is your column of data points and <value> is your completely separate number.

Subject: Rounding to nearest data point.

From: Jos (10584)

Date: 11 Mar, 2010 15:02:21

Message: 3 of 3

"jmeccles Eccles" <jared.eccles@hotmail.com> wrote in message <hnaso9$fdo$1@fred.mathworks.com>...
> I have a column of data points, and my function is taking in a completely separate number from these points. I want to be able to round this number to the nearest point from my column of data points.
>
> Any help is greatly appreciated.
>
> Thanks in advance.

help interp1

Data = 0:10:50
P = 22
idx = interp1(Data,1:numel(Data),P,'nearest') ;
nearestData = Data(idx)


Jos

Tags for this Thread

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
rounding jmeccles 11 Mar, 2010 08:59:21
rssFeed for this Thread

Contact us at files@mathworks.com