MATLAB: How do you split up a matrix into 2 matrices where the rows are made up of the rows from the initial matrix containing certain numbers

MATLABmatrixmatrix arraymatrix manipulation

How do you split up a matrix into 2 matrices were the rows are made up of the rows from the initial matrix containing certain numbers?
For example if I have the matrix,
J = [1 2 3 77 5; 77 1 2 77 3; 1 2 3 4 5; 1 2 3 4 5; 1 77 3 4 5; 1 2 3 4 5]
and I want,
A = [1 2 3 77 5; 77 1 2 77 3; 1 77 3 4 5]
and,
B = [1 2 3 4 5; 1 2 3 4 5; 1 2 3 4 5]
So far I have the code shown below, but I am not 100% sure if this is correct?
if true
% rows=size(J,1);
cols=size(J,2);
for i=1:1:rows
for u=1:1:cols
if J(i,u)==77
B=[
end
Any help would be appreciated, thanks!

Best Answer

Contain77InRow=any(J==77,2);
A=J(Contain77InRow,:)
B=J(~Contain77InRow,:)