iteration in bootstrap method
2 次查看(过去 30 天)
显示 更早的评论
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);
0 个评论
采纳的回答
Adam Danz
2018-6-23
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}
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!