iteration in bootstrap method

2 visualizaciones (últimos 30 días)
Yu Zhang
Yu Zhang el 19 de Jun. de 2018
Comentada: Yu Zhang el 27 de Jun. de 2018
HI guys, i have a 1*39 cell array (M) and each cell contains different dimension numeric arrays(e.g. 74*3,68*3...), for each column i want to resample it with bootstrap. I guess boot function could only be applied on array numbers so i created M_1 to capture each column in the cell array. (i also tried to convert the whole cell table to array but did not succeed.) How can i put the code down below into a for loop and get the numeric arrays? Thank you so much if you could help.
M_1=M{1,1}(:,2);
[stats,bootsam]= bootstrp(100,@(x)[mean(x) std(x) moment(x,4) moment(x,3)],M_1);

Respuesta aceptada

Adam Danz
Adam Danz el 23 de Jun. de 2018
Follow this example. I loop through all elements of M and then all columns within each element of M.
% fake data
M = {rand(74,3); rand(68,3); rand(22,4)};
% get number of columns in each M
nCols = cellfun(@(x)size(x,2), M);
% initialize loop vars
stats = cell(length(M), max(nCols));
bootsam = stats;
% Loop through your cell array
for i = 1:length(M) %for each element of M
for j = 1:size(M{i},2) %for each column of M{i}
[s,b]= bootstrp(100,@(x)[mean(x) std(x) moment(x,4) moment(x,3)],M{i}(:,j));
stats{i,j} = s; %store values
bootsam{i,j} = b; %store values
end
end
% To get the results for M{1} column(2)
stats{1,2}
bootsam{1,2}

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by