Picking arrays from a matrix based on a condition
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponse acceptée
Bruno Luong
le 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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!