Clear Filters
Clear Filters

Picking arrays from a matrix based on a condition

3 views (last 30 days)
Hi,
I have a matrix:
3 3 3 3 3 2 2 2 4 4
4 4 4 4 4 2 2 4 4 4
5 5 5 5 5 2 2 4 4 4
6 6 6 6 6 2 2 2 4 4
Suppose the first five elements in any row are represented by A (e.g., always the same value. for instance 3 in the first row) while the last five elements always include only two numbers i.e. B (equal to 2, in the first row) and C (equal to 4, in the first row)
How would I be able to pick those rows that hold: B<A<C. For instance, the below rows in the above case:
3 3 3 3 3 2 2 4 4 4
4 4 4 4 4 2 2 4 4 4
Many thanks.

Accepted Answer

Bruno Luong
Bruno Luong on 22 Oct 2018
M=[3 3 3 3 3 2 2 2 4 4;
4 4 4 4 4 2 2 4 4 4;
5 5 5 5 5 2 2 4 4 4;
6 6 6 6 6 2 2 2 4 4]
[A,B,C]=deal(M(:,1),M(:,6),M(:,9));
M(B<=A & A<=C,:) % Not same criteria stated in your question
Gives:
ans =
3 3 3 3 3 2 2 2 4 4
4 4 4 4 4 2 2 4 4 4

More Answers (0)

Categories

Find more on Matrices and Arrays 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!