Splitting a matrix into two smaller matrices in a loop
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Unqua Laraib
el 22 de Abr. de 2021
Comentada: Unqua Laraib
el 22 de Abr. de 2021
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 comentarios
Respuesta aceptada
Matt J
el 22 de Abr. de 2021
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
Más respuestas (0)
Ver también
Categorías
Más información sobre Parallel and Cloud en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!