iteration in bootstrap method

조회 수: 2 (최근 30일)
Yu Zhang
Yu Zhang 2018년 6월 19일
댓글: Yu Zhang 2018년 6월 27일
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);

채택된 답변

Adam Danz
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}
  댓글 수: 1
Yu Zhang
Yu Zhang 2018년 6월 27일
Thank you so much!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by