Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Removing a range from an array

Subject: Removing a range from an array

From: Michael

Date: 19 Oct, 2013 18:00:09

Message: 1 of 4

i have a range of angular data (0-360) degrees in a vector, and I want to only keep specific elements in this Vector. I want to only keep values that meet the following criteria for vector x...

22.5 <= x < 67.5 & 202.5<= x < 247.5

Any help you could provide would be great. I can get rid of the values < 22.5 and >=247.5 but the middle values I'm having an issue with.

Please let me know if you have a way of doing this.

Thanks,
Mike

Subject: Removing a range from an array

From: dpb

Date: 19 Oct, 2013 18:08:44

Message: 2 of 4

On 10/19/2013 1:00 PM, Michael wrote:
> i have a range of angular data (0-360) degrees in a vector, and I want
> to only keep specific elements in this Vector. I want to only keep
> values that meet the following criteria for vector x...
>
> 22.5 <= x < 67.5 & 202.5<= x < 247.5
>
> Any help you could provide would be great. I can get rid of the values <
> 22.5 and >=247.5 but the middle values I'm having an issue with.
>
> Please let me know if you have a way of doing this.

 > type iswithin.m

function flg=iswithin(x,lo,hi)
% returns T for values within range of input
% SYNTAX:
% [log] = iswithin(x,lo,hi)
% returns T for x between lo and hi values, inclusive

   flg= (x>=lo) & (x<=hi);

 >>

y=x(iswithin(x,22.5,67.5) & iswithin(x,202.5,247.5));

--

Subject: Removing a range from an array

From: dpb

Date: 19 Oct, 2013 18:10:23

Message: 3 of 4

On 10/19/2013 1:08 PM, dpb wrote:
...

> y=x(iswithin(x,22.5,67.5) & iswithin(x,202.5,247.5));
>
ERRATUM:

y=x(iswithin(x,22.5,67.5) | iswithin(x,202.5,247.5));

Need 'or', not 'and'

--

Subject: Removing a range from an array

From: dpb

Date: 20 Oct, 2013 15:34:04

Message: 4 of 4

On 10/19/2013 1:10 PM, dpb wrote:
> On 10/19/2013 1:08 PM, dpb wrote:
> ...
>
>> y=x(iswithin(x,22.5,67.5) & iswithin(x,202.5,247.5));
>>
> ERRATUM:
>
> y=x(iswithin(x,22.5,67.5) | iswithin(x,202.5,247.5));
>
> Need 'or', not 'and'
>

ADDENDUM:

Or, conversely, if don't need the original input any longer eliminate
the converse...


x(~(iswithin(x,22.5,67.5) | iswithin(x,202.5,247.5)))=[];

Hopefully I counted/matched paren's correctly... :)

--

Tags for this Thread

No tags are associated with this thread.

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.

Contact us