COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### find and replace elements of a matrix?

• Follow

```I have a matrix with a few thousand of lines and 3 columns (x, y, z).
I want to do the following:
- if x(i) is between a1 and a2
"and"
- if y(i) is between b1 and b2
then z(i)=0.

I have to repeat the above sequence 10 times (for different "a" and "b" values). How can I do it fast?

Thank you!
```
 0

```"Doru F" <doruforum@yahoo.com> wrote in message <i7a791\$fee\$1@fred.mathworks.com>...
> I have a matrix with a few thousand of lines and 3 columns (x, y, z).
> I want to do the following:
>  - if x(i) is between a1 and a2
> "and"
>  - if y(i) is between b1 and b2
> then z(i)=0.
>
> I have to repeat the above sequence 10 times (for different "a" and "b" values). How can I do it fast?
>
> Thank you!

place it in a for loop...
z(x > a1 & x < a2 & y > b1 & y < b2) = 0;

Or if you know which values are between the a1,a2 and b1,b2 for all the 10 times use ismember without looping.

Oleg
```
 0

1 Replies
1294 Views

Similiar Articles:

7/21/2012 10:45:31 PM