How can I randomize cube positions in matlab?

3 ビュー (過去 30 日間)
Mint
Mint 2021 年 6 月 22 日
編集済み: Mint 2021 年 6 月 22 日
I have generated 10 different cube positions in v and now I want to randomize the order of the positions, i.e. the columns, so that I have 10 different orders of v. Unfortunately it doesn't work with the loop and I only get one randomized order in B.
I am grateful for your help!
E=1;
N=3;
Nsamples=10;
d=randi(N,1,Nsamples);
s=randi(2,1,Nsamples)-1;
v=rand(N,Nsamples);
for i=1:Nsamples
v(d(i),i)=s(i);
end
v=E*v;
plot3(v(1,:),v(2,:),v(3,:),".");
for i=1:10
x = randperm(size(v,2)); % Create list of integers 1:n, in random order,
% where n = num of columns
B = v(:, x); % Shuffles columns about, on all rows, to indixes in x

採用された回答

Alan Stevens
Alan Stevens 2021 年 6 月 22 日
Like this?
E=1;
N=3;
Nsamples=10;
d=randi(N,1,Nsamples);
s=randi(2,1,Nsamples)-1;
v=rand(N,Nsamples);
for i=1:Nsamples
v(d(i),i)=s(i);
end
v=E*v;
plot3(v(1,:),v(2,:),v(3,:),".");
n = size(v,2);
B = zeros(3,n,10);
for i = 1:10
x = randperm(n); % Create list of integers 1:n, in random order,
% where n = num of columns
B(:,1:n,i) = v(:, x); % Shuffles columns about, on all rows, to indixes in x
end
  1 件のコメント
Mint
Mint 2021 年 6 月 22 日
編集済み: Mint 2021 年 6 月 22 日
Yes, that solves my problem!
Thank you :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by