필터 지우기
필터 지우기

Splitting a matrix into two smaller matrices in a loop

조회 수: 3 (최근 30일)
Unqua Laraib
Unqua Laraib 2021년 4월 22일
댓글: Unqua Laraib 2021년 4월 22일
Suppose i have a small matrix of size 10x10. I also have an array which has predifiened indexes it looks like this as an example: ind = [1;2;4;6;8;10].
I simply want to run a loop in which the original matrix will be split into train and test matrices. In first iteration the test matrix will have number of rows (or sample) according to ind(1) and all columns (or features) and rest of all the rows will go in train matrix. Similarly, in second iteration the test matrix will have number of rows (or sample) according to ind(2) and all columns (or features) and rest of all the rows will go in train matrix. The logic is that those rows which appear in test will not appear in train in that iteration. How can i achieve this? I was able to define Test matrix but 't unable to come up with the logic for train matrix. please look at the code i provided.
with these train and test set i want to train and test SVM and calculate the accuracy.
As you gussed it im trying to do Leave one out cross validation in my own way!
% My_Data is the 10x10 matrix. it has random values
z=[1;2;4;6;8;10]; % specific indexs
for k=1:length(z)
test=My_Data(z(k):z(k+1),:);
% how to define train set
end

채택된 답변

Matt J
Matt J 2021년 4월 22일
z=[1;2;4;6;8;10];
for k=1:length(z)
ind=z(k):z(k+1);
test=My_Data(ind,:);
train=MyData;
train(ind,:)=[];
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Hypothesis Tests에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by