Thread Subject: Filtering

Subject: Filtering

From: Jesper Lauridsen

Date: 1 Aug, 2009 07:47:56

Message: 1 of 3

If I have a vector named x:

x=[20 15 10 5 0.5 0.2 0.1 0 -0.1 -0.3 -0.5 -1 -3 -5]

What I am interested in is to filter the data in the vector. I want 0.5>x>-0.5 set to zero. This means the vector x after filtering should look like:


x=[20 15 10 5 0 0 0 0 0 0 0 -1 -3 -5]

I tried

x(x<=0.5 && x>=-0.5)=0

??? Operands to the || and && operators must be convertible to logical scalar values.


x(x<=0.5)=0 && x(x>=-0.5)=0

Error: The expression to the left of the equals sign is not a valid target for an assignment.

Subject: Filtering

From: Rune Allnor

Date: 1 Aug, 2009 11:05:01

Message: 2 of 3

On 1 Aug, 09:47, "Jesper Lauridsen" <jesperhols...@hotmail.com> wrote:
> If I have a vector named x:
>
> x=[20 15 10 5 0.5 0.2 0.1 0 -0.1 -0.3 -0.5 -1 -3 -5]
>
> What I am interested in is to filter the data in the vector. I want 0.5>x>-0.5 set to zero. This means the vector x after filtering should look like:
>
> x=[20 15 10 5 0 0 0 0 0 0 0 -1 -3 -5]
>
> I tried
>
> x(x<=0.5 && x>=-0.5)=0
>
> ??? Operands to the || and && operators must be convertible to logical scalar values.
>
> x(x<=0.5)=0 && x(x>=-0.5)=0
>
> Error: The expression to the left of the equals sign is not a valid target for an assignment.

>> x=[20 15 10 5 0.5 0.2 0.1 0 -0.1 -0.3 -0.5 -1 -3 -5]';
>> x(abs(x)<=0.5)=0

x =

    20
    15
    10
     5
     0
     0
     0
     0
     0
     0
     0
    -1
    -3
    -5

Rune

Subject: Filtering

From: Hariton Ul'ianov

Date: 1 Aug, 2009 11:34:03

Message: 3 of 3

Hi, colleague!
Try this:

clear;
x=[20 15 10 5 0.5 0.2 0.1 0 -0.1 -0.3 -0.5 -1 -3 -5];
 for ii=1:length(x)
     if x(ii)<=0.5 && x(ii)>=-0.5
         x(ii)=0;
     end
 end

Best regards, Me.

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
logical operators Povl Bevington 1 Aug, 2009 03:48:11
rssFeed for this Thread

Contact us at files@mathworks.com