Separating Matrix Rows into two different vectors

I have a matrix
A=[1 3 5;1 5 6;3 9 10;3 5 6;1 4 5;3 5 6; 9 6 7; 1 5 8; 3 6 0];
and i would like to seperate in in terms of the 1st element
for example
if A(1,i)==1 then it would a adn if A(1,i)== 3 then it would go into b and i would like A to reduce in size as it goes to one matrix or another.
So when I have the first row after it gets assigned into a vector i want it to be deleted and goes to the next one
so i want my final results to look like
A=[9 6 7]
a=[1 3 5;1 5 6;1 4 5;1 5 8]
b=[3 9 10;3 5 6;3 5 6; 3 6 0]
How would that be done?
And, if I had this condition
A(1)<2 put in a matrix if greater than >2 put in b matrix. and the format would look like this:
A=[9 6 7]
a=[1 3 5;1 5 6;1 4 5;1 5 8]
b=[3 9 10;3 5 6;3 5 6; 3 6 0]
How would it be done?

 Akzeptierte Antwort

Matt J
Matt J am 23 Jan. 2021
Bearbeitet: Matt J am 23 Jan. 2021
A=[1 3 5;1 5 6;3 9 10;3 5 6;1 4 5;3 5 6; 9 6 7; 1 5 8; 3 6 0];
groups=splitapply( @(X) {X} , A , findgroups(A(:,1)) );
[a,b,A]=deal(groups{:})
a = 4×3
1 3 5 1 5 6 1 4 5 1 5 8
b = 4×3
3 9 10 3 5 6 3 5 6 3 6 0
A = 1×3
9 6 7

4 Kommentare

A
A am 27 Jan. 2021
Thank you for your response just wondering what is X? Where did it come from?
Matt J
Matt J am 28 Jan. 2021
Bearbeitet: Matt J am 28 Jan. 2021
@(X) {X} is an anonymous function. X is just a parameter of the function.
A
A am 29 Jan. 2021
I see that makes sense,
Thank you
Matt J
Matt J am 29 Jan. 2021
You're welcome, but please Accept-click the answer if it resolves your question.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Gefragt:

A
A
am 23 Jan. 2021

Kommentiert:

am 29 Jan. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by