How can I randomize cube positions in matlab?

3 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Alan Stevens
Alan Stevens il 22 Giu 2021
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 Commento
Mint
Mint il 22 Giu 2021
Modificato: Mint il 22 Giu 2021
Yes, that solves my problem!
Thank you :)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Random Number Generation in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by