Randomizing the picking and changing of values in a 3D array

3 ビュー (過去 30 日間)
Filip Hansson
Filip Hansson 2022 年 8 月 16 日
コメント済み: Filip Hansson 2022 年 8 月 18 日
I have a 24x365x60 array and would like to set 4 of the 24 values for each of the 365 columns to a constant (11), based on a 24x365 matrix with "1"s in the particular positions, for a randomized 30 of the 60 sheets (third dimemsion) and letting the other 30 beeing unchanged. What is the best way to solve this?

採用された回答

Jan
Jan 2022 年 8 月 16 日
編集済み: Jan 2022 年 8 月 17 日
x = zeros(24, 365, 60);
m3 = randperm(60, 30);
for i3 = m3
for i2 = 1:365
m1 = randperm(24, 4);
x(m1, i2, i3) = 11;
end
end
sum(x(:) == 11)
ans = 43800
Is this the wanted number of 11's? 4*365*30 = 43800
  8 件のコメント
Jan
Jan 2022 年 8 月 18 日
You want to replace randperm(24, 4)? Okay then simply replace this command in my code.
A short example would clarify, what you want to do exactly.
Filip Hansson
Filip Hansson 2022 年 8 月 18 日
I saw the solution from you in another tread and it worked lika a charm!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by