# split matrix into two based on column values

8 vues (au cours des 30 derniers jours)
Abhiram B R le 25 Mai 2021
Hi all,
I need to split a matrix into two based on values in last column of matrix. An example is given below:
A = [ 1 2 1.4; 1 3 1.4; 2 5 1.4; 1 5 81; 3 4 1.4; 5 4 81]
this need to be split into two
one matrix with [1 5 81;5 4 81] and other with rest of the elements of A. Basically if value of column 3 is greater than 80, save it into another matrix. Is it possible to do so without writing a loop
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Stephan le 25 Mai 2021
A = [ 1 2 1.4; 1 3 1.4; 2 5 1.4; 1 5 81; 3 4 1.4; 5 4 81]
A = 6×3
1.0000 2.0000 1.4000 1.0000 3.0000 1.4000 2.0000 5.0000 1.4000 1.0000 5.0000 81.0000 3.0000 4.0000 1.4000 5.0000 4.0000 81.0000
A1 = A(A(:,end)>80,:)
A1 = 2×3
1 5 81 5 4 81
A2 = A(A(:,end)<=80,:)
A2 = 4×3
1.0000 2.0000 1.4000 1.0000 3.0000 1.4000 2.0000 5.0000 1.4000 3.0000 4.0000 1.4000
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by