mardi 10 décembre 2019

Dividing a matrices in to two part

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

class_id = search(:,4);
for s=i : j

if  class_id == 1 

    Q1 = search(s,1:4)

elseif class_id == 2 

    Q2 = search(s,1:4)
end
end

Briefly I am trying to divide my dataset into two parts using for loops and if statements.For this code there is no error but outcome is wrong.Below I add my dataset and outcome.

Outcome 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

And Q2 =

  • 34 59 0 2
  • 34 66 9 2

Aucun commentaire:

Enregistrer un commentaire