Question on nested forloops to call on a value for bootstrapping 95% confidence intervals

조회 수: 1 (최근 30일)
I'm new to MATLAB and need help with thinking out a forloop.
I have 18 excel sheets with each other looking like the following:
My end goal is to have a forloop that will first randomly pick a # from the first column (a value 1 through 20 with some values missing sometimes) then randomly pick an image number and then randomly pick a particle number and have it step through that sequence 10,000 times and create a new dataset. From that, I will be calculating 95% confidence intervals using bootstrapping.
What I have right now is this:
data=[cellsize,biomass];
numpoints=length(data(:,1));
for i=1:10000
indices=ceil(rand(numpoints,1)*numpoints);
data_tempbootstrap=data(indices,:);
boot_mean(i)=geomean(data_tempbootstrap(:,1) ...
./data_tempbootstrap(:,2));
end
figure
hist(boot_mean,100)
boot_mean=sort(boot_mean);
len=length(boot_mean);
CIlow=boot_mean(round(len*0.025))
CIhigh=boot_mean(round(len*0.975))
However that is just running through the entire list of cell sizes and biomass, not randomly selecting a number, then an image number and then a particle number. I know I need to add a nested forloop inside that forloop that will randomly call on a particle, i just don't know how to do it and I'm getting overwhelmed trying to figure it out. Thank you for any help, again I'm new at matlab and am still learning the basics.
  댓글 수: 2
Jeff Miller
Jeff Miller 2022년 6월 29일
Not exactly sure what you want to do, but from your description it sounds like you want to implement something like the following pseudo code:
for i=1:10000
for j=1:numpoints
thisNumber = ?; % randomly choose one of the values in the 1st column
thisImage = ?; % randomly choose one of the values in the 2nd column
thisPart = ?; % randomly choose one of the values in the 3rd column
rowNum = ?; % find the row corresponding to the chosen number, image, particle
data_tempbootstrap(j,1) = cellsize(rowNum);
data_tempbootstrap(j,2) = biomass(rowNum);
end
boot_mean(i)=geomean(data_tempbootstrap(:,1) ...
./data_tempbootstrap(:,2));
end
But I'm not sure how this is different than just choosing a row randomly, which is what you are doing now. I guess it depends on what combinations you have of the different values in the 1st 3 columns.
Anyway, if this is the right pseudocode to describe your plan, then it shouldn't be too hard to fill in the ?'s (except maybe for the issue of what to do when there is no row with the selected combination of Number, Image, and Part).
iceskating911
iceskating911 2022년 6월 29일
Thank you! I realize I didn't write enough detail but that gave me some ideas of where to go from here, thanks!

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Big Data Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by