How can I randomize cube positions in matlab?

1 Ansicht (letzte 30 Tage)
Mint
Mint am 22 Jun. 2021
Bearbeitet: Mint am 22 Jun. 2021
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

Akzeptierte Antwort

Alan Stevens
Alan Stevens am 22 Jun. 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 Kommentar
Mint
Mint am 22 Jun. 2021
Bearbeitet: Mint am 22 Jun. 2021
Yes, that solves my problem!
Thank you :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Random Number Generation finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by