Is it possible to use cell indices (specified in large 3D arrays) to call specific data out of another 3D array?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
更多回答(2 个)
Walter Roberson
2018-7-25
cellr(:,:,i) = round(length(tP) .* rand(n,mc));
can be 0.
Perhaps it would make more sense to use randi() ?
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!