Splitting a matrix into two smaller matrices in a loop
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Parallel and Cloud 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!