Without using
Q1 = search(search(:,4)==1,:)
Q2 = search(search(:,4)==2,:)
I am trying to classify my dataset. To do this, I will use the 4th column of my dataset. If the 4th column of the dataset is equal to 1, that row will added in new matrix called Q1. If the 4th column of the dataset is equal to 2, that row will be added to matrix Q2.
My code:
i = input('Enter a start row: ');
j = input('Enter a end row: ');
search = importfiledataset('search-queries-features.csv',i,j);
[n, p] = size(search);
if j>n
disp('Please enter a smaller number!');
end
for s = i:j
class_id = search(s,4);
if class_id == 1
Q1 = search(s,1:4)
elseif class_id ==2
Q2 = search(s,1:4)
end
end
This calculates the Q1 and Q2 matrices, but they all are 1x4 and when it gives new Q1 the old one is deleted. I need to add new row and make it 2x4 if conditions are true. I need to expand my Q1matrix.
Briefly I am trying to divide my dataset into two parts using for loops and if statements.
Dataset:
I need outcome like:
Q1 = [30 64 1 1;
30 62 3 1;
30 65 0 1;
31 59 2 1;
31 65 4 1;
33 58 10 1;
33 60 0 1;
34 58 30 1;
34 60 1 1 ;
34 61 10 1;]
Q2 = [34 59 0 2;
34 66 9 2;]
How can I prevent my code from deleting previous rows of Q1 and Q2 and obtain the entire matrices?