how to create and store a matrix from a dataset comprising of certain rows from the dataset.

조회 수: 2 (최근 30일)
Need to create a matrix from a dataset that selects certain rows depending on whether a given condition is fulfilled. For eg, from the IRIS dataset, create a matrix comprising of first 30 samples for each class.

채택된 답변

KSSV
KSSV 2019년 2월 27일
load iris.dat
setosa = iris((iris(:,5)==1),:); % data for setosa
versicolor = iris((iris(:,5)==2),:); % data for versicolor
virginica = iris((iris(:,5)==3),:); % data for virginica
obsv_n = size(iris, 1); % total number of observations
  댓글 수: 1
Apurva Jariwala
Apurva Jariwala 2019년 2월 27일
Thanks for the response, i have written the following code to divide the iris dataset into training and testing dataset. Any help to reduce the lines of code is appreciated
setosa = Tnew((Tnew(:,5)==1),:); %Tnew is the iris dataset
Ttest1 = setosa(1:40,:);
Ttrain1 = setosa(41:50,:);
versicolor = Tnew((Tnew(:,5)==2),:);
Ttest2 = versicolor(1:40,:);
Ttrain2 = versicolor(41:50,:);
virginica = Tnew((Tnew(:,5)==3),:);
Ttest3 = virginica(1:40,:);
Ttrain3 = virginica(41:50,:);
Ttest = [Ttest1; Ttest2; Ttest3];
Ttrain = [Ttrain1; Ttrain2; Ttrain3];

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by