Is it possible to use cell indices (specified in large 3D arrays) to call specific data out of another 3D array?

1 回表示 (過去 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 件のコメント
Adam Danz
Adam Danz 2018 年 7 月 25 日
編集済み: Adam Danz 2018 年 7 月 25 日
Which line is producing the error? The one that produces 'datar' ?
Brigitta Rongstad
Brigitta Rongstad 2018 年 7 月 25 日
simr(r,c,i) = datar(cell,depth,i) line

サインインしてコメントする。

採用された回答

Adam Danz
Adam Danz 2018 年 7 月 25 日
編集済み: Adam Danz 2018 年 7 月 25 日
Without having the values to your variables, I can only guess.
Test these ideas
  • the value of 'cell' is not a positive integer
  • the value of 'depth' is not a positive integer

その他の回答 (2 件)

Walter Roberson
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() ?

Brigitta Rongstad
Brigitta Rongstad 2018 年 7 月 25 日
I realized one line of my code didn't exclude zeros from being randomly sampled. Once that is fixed, the code runs just fine!

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by