dvide 500 random color to 80 different basket

2 visualizaciones (últimos 30 días)
shalom kobi
shalom kobi el 3 de Mayo de 2021
Comentada: shalom kobi el 4 de Mayo de 2021
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

Respuesta aceptada

shalom kobi
shalom kobi el 4 de Mayo de 2021
clear all
clc
% define my deck 100 ball each color
for i=1:100
deck_num(i,:) =( [1,2,3,4,5]'); % test
i=i+5;
end
%dvide to 80 basket for 500 balls
r=randi([1,80],1,500);
for i=1:500
x=(r(i)); % go to number of busket
deck_b(i,r(i))=deck_num(i);
end
% count how many are in the basket from each color
for i=1:80
s1=numel(find(deck_b(:,i)==1)); % count the red color
s2=numel(find(deck_b(:,i)==2)); % count the green color
s3=numel(find(deck_b(:,i)==3)); % count the purple color
s4=numel(find(deck_b(:,i)==4)); % count the yellow color
s5=numel(find(deck_b(:,i)==5)); % count the blue color
basket(:,i)=[s1 s2 s3 s4 s5]; % final result culom 1:80 are basket and row 1:5 (vector) define 5 different color
end

Más respuestas (1)

KSSV
KSSV el 4 de Mayo de 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 comentarios
shalom kobi
shalom kobi el 4 de Mayo de 2021
no i dont know what should be in each busket
its an experiment and each time i run the code i exept to different soulotion ( randomly)
shalom kobi
shalom kobi el 4 de Mayo de 2021
hey
i resolve the issue
you can check the code i upload

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by