How can I vectorize this piece of code for loading cross-validation from file ?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Dang Manh Truong
am 19 Nov. 2016
Kommentiert: Dang Manh Truong
am 19 Nov. 2016
So I am supposed to load the cross-validation folds from a file (10 iterations, each is 10-folds, so a total of 100, arranged sequentially in a 1-dimensional array). I have attached the file below. The problem is my code uses for loops intensively and I would like to vectorise it, here is my code:
input_filename = 'cv_yeast.mat';
cv = load(input_filename);
nfolds= 10;
niters = 10;
for loop =1:niters
for i = 1 : nfolds
teIdx = cv.cv{((loop-1)*nfolds + i)};
trIdx = [];
for j = 1 : nfolds
if j ~= i
trIdx = [trIdx; cv.cv{(loop - 1)*nfolds + j}];
end
end
% Processing goes here
end
end
For some reasons I don't want to vectorise the 2 outer for loops, just the inner one. Can anyone help me, thank you very much :)
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 19 Nov. 2016
Possibly
jv = setdiff(1 : nfolds, i);
trIdx = vertcat( cv.cv{(loop - 1)*nfolds + jv} );
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!