dvide 500 random color to 80 different basket
Mostra commenti meno recenti
hey
im trying to make a code that recive 500 ball ( 100 of each color : red blue yellow green purple)
then i want matlab will dvide this 500 ball randomly to 80 different basket
i have tryd few command and loops without succses
here is my code so far
%%
clear all
clc
for i=1:100
%deck(i,:) =( ["1","2","3","4","5"]' ); test
deck(i,:) =( ["R","G","P","Y","B"]' );
i=i+5;
end
n=0; % counter
%r=randi([1,80],1,500);
for i=1:500
temp=(randi([1,80]));
n=n+1;
K(n,:)=temp;
end
% not sure if nessacery
A=zeros (500,80);
B=zeros (500,80);
%dvide the 500 ball to 80 basket
for i=1:500
temp=deck(i);
tempb=K(i);
A(tempb,:)=temp;
B(:,tempb)=temp;
C(:,K(i))=deck(i);
D(K(i,:))=deck(i);
%F=struct(tempb,temp);
%data.K(i,:)=deck(i);
%data(K(i,:)).tempb=deck(i);
random(K(i,:)).tempb=deck(i);
end
i will appriciate any help to solve this problem
Risposta accettata
Più risposte (1)
KSSV
il 4 Mag 2021
N = 100 ;
R = ones(N,1) ;
B = 2*ones(N,1) ;
Y = 3*ones(N,1) ;
G = 4*ones(N,1) ;
P = 5*ones(N,1) ;
balls = [R; B; Y; G; P] ;
% randomise the order
balls = balls(randperm(length(balls)))
% choose any 80 balls out of it
iwant = balls(randperm(length(balls),80))
4 Commenti
shalom kobi
il 4 Mag 2021
Modificato: shalom kobi
il 4 Mag 2021
KSSV
il 4 Mag 2021
You already know what should be there in each basket...... what is there to solve now and code?
shalom kobi
il 4 Mag 2021
shalom kobi
il 4 Mag 2021
Categorie
Scopri di più su Mathematics in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!