How can I randomize cube positions in matlab?

3 次查看(过去 30 天)
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Random Number Generation 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by