how to do leave-one-out cross validation of samples in cells

1 Ansicht (letzte 30 Tage)
ML
ML am 11 Mai 2016
Bearbeitet: Stephen23 am 11 Mai 2016
Given a cell array C {1x 50}, how can I create leave-one-out loop such that in each of the 50 loops a different cell is "removed" from C and stored in a matrix, and the remaining 49 cells are vertically concatenated in another matrix(C{1};C{2};C{3};...).
So, in each loop two matrices are created; 1- vertically concatenated 49 cells 2- the 1 removed cell

Akzeptierte Antwort

Stephen23
Stephen23 am 11 Mai 2016
Bearbeitet: Stephen23 am 11 Mai 2016
C = num2cell(1:50);
Method One: Colon Operator
N = numel(C);
for k = 1:N
ind = C{k}
tmp = vertcat(C{[1:N-1,N+1:end]})
end
Method Two: setdiff
vec = 1:numel(C);
for k = vec
ind = C{k}
tmp = vertcat(C{setdiff(vec,k)})
end

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements 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!

Translated by