How can I randomize cube positions in matlab?
조회 수: 1 (최근 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
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Random Number Generation에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!