How to extract rows which contains a specific value in each row.

How to extract rows which contains a specific value in each row. Example: a =
1. 2. 3.
4. 5. 6.
1. 2. 3.
4. 5. 6.
a(a==1,:)
1. 2. 3.
1. 2. 3.
but the problem is as follows:
a(a==5,:)
Invalid index.

 Accepted Answer

You need to use any:
>> a(any(a==1,2),:)
ans =
1 2 3
1 2 3
>> a(any(a==5,2),:)
ans =
4 5 6
4 5 6

2 Comments

If i have a large matrix and i don't know how many rows which contain the value 5, how i can use the function any.
@slimani djamel: exactly like I showed you. It does not matter how many rows there are. Did you try it?

Sign in to comment.

More Answers (1)

Categories

Find more on Networks in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!