Is it possible to use cell indices (specified in large 3D arrays) to call specific data out of another 3D array?
1 view (last 30 days)
Show older comments
Brigitta Rongstad
on 25 Jul 2018
Answered: Brigitta Rongstad
on 25 Jul 2018
I need to randomly sample data (70 samples, repeated 10,000 times) from a large temperature dataset (3D array) using cell indices specified in separate 3D arrays. I am able to generate 3D arrays specifying the cell indices for each dimension, but I am having issues using those indices to then call specific data from my original data set. When I try to use a for loop to sort through each dimension of the array and select the data I get the "subscript indices must either be real positive integers or logicals" which I realize has something to do with how I'm calling the data. My attempt to select data is at the end of my code below.
n = 70;
mc = 10000;
for i=1:9
%randomly sample a depth using normal dist centered at m with stdev s
mu = median(surf1:surf2);
sigma = 1;
depthr(:,:,i) = round(sigma .* randn(n,mc) + mu);
depthr(depthr < surf1) = surf1;
depthr(depthr > surf2) = surf2;
%randomly sample cell numbers
cellr(:,:,i) = round(length(tP) .* rand(n,mc));
%select site data
datar(:,:,i) = tP(:,:,min(find(round(lat) == round(corelat(i)))),...
min(find(round(lon) == round(corelon(i)))));
end
for i=1:9
for c=1:mc
for r=1:n
cell = cellr(r,c,i);
depth = depthr(r,c,i);
simr(r,c,i) = datar(cell,depth,i);
end
end
end
2 Comments
Accepted Answer
More Answers (2)
Walter Roberson
on 25 Jul 2018
cellr(:,:,i) = round(length(tP) .* rand(n,mc));
can be 0.
Perhaps it would make more sense to use randi() ?
0 Comments
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!