MATLAB: How to create 2 different matrices from 1 matrix

MATLABmatrix

I have a database 749×5 size. What I want is:
I created a matrix from this dataset. I called it matrix. Then, the last column of my matrix is class. I have two classes. If last column is zero, then this row belongs to c0 (class 0), and if the last column is 1 then this row belong to c1 (class 1). I wrote a code. In the c0 there is no problem but in c1, there is zeros then appears its real values. But I do not want the zeros. Can you help me, please?
mSize = 5, atributeNums=4 in my database.
Here is my code:
mSize = size(matrix,2);
c0= zeros();
c1= zeros();
k = 1;
for i=1:size(matrix,1) - 1
for j=1:attributesNum
if matrix(i,mSize)== 0
c0(i,j)= matrix(i,j);
end
for a=1:attributesNum
if matrix(i,mSize)~= 0
c1(i,k)= matrix(i,j);
k = k+1;
end
end
end
end
c1 expected matrix:
2 6 1500 47
4 2 500 9
2 2 500 11
...
21 2 500 52
23 3 750 62
39 1 250 39
c1 output
0 0 0 0
0 0 0 0
0 0 0 0
....
2 6 1500 47
4 2 500 9
2 2 500 11
...
21 2 500 52
23 3 750 62
39 1 250 39

Best Answer

mask = matrix(:,end) == 0;
c0 = matrix(mask,:);
c1 = matrix(~mask,:);
No loops needed.