generating random for j elemnts in matrix from set of data i have
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Kamal Ebrahimi
le 28 Nov 2018
Commenté : madhan ravi
le 28 Nov 2018
How can i generate random variable for j elemnts in my matrix from set of data i've?
i'm trying to write a code for to generate random cases for doing simple data research , i'll be grateful if someone helps me with it , this is my code:
patient_condition=[0.05; 0.15; 0.25; 0.35; 0.45; 0.55; 0.65; 0.75; 0.85; 0.95];
test_type=[0.1 0.26 0.42 0.58 0.74 0.9];
patient_origin=[0.12 0.23 0.34 0.45 0.56 0.67 0.78 0.89];
doctor_orogin=[0.02 0.212 0.404 0.596 0.788 0.98];
patient_age=[0.15 0.4 0.65 0.9];
insurance=[0.04 0.26 0.48 0.7 0.92];
hospital=[0.06 0.24 0.42 0.6 0.77 0.96];
for j=1:1000
p(1,j)=patient_condition(randi(patient_condition));
p(2,j)=test_type(randi(test_type));
p(3,j)=patient_origin(randi(patient_origin));
p(4,j)=doctor_orogin(randi(doctor_orogin));
p(5,j)=patient_age(randi(patient_age));
p(6,j)=insurance(randi(insurance));
p(7,j)=hospital(randi(hospital));
end
0 commentaires
Réponse acceptée
madhan ravi
le 28 Nov 2018
Modifié(e) : madhan ravi
le 28 Nov 2018
EDITED
I think you mean
patient_condition=[0.05; 0.15; 0.25; 0.35; 0.45; 0.55; 0.65; 0.75; 0.85; 0.95];
test_type=[0.1 0.26 0.42 0.58 0.74 0.9];
patient_origin=[0.12 0.23 0.34 0.45 0.56 0.67 0.78 0.89];
doctor_orogin=[0.02 0.212 0.404 0.596 0.788 0.98];
patient_age=[0.15 0.4 0.65 0.9];
insurance=[0.04 0.26 0.48 0.7 0.92];
hospital=[0.06 0.24 0.42 0.6 0.77 0.96];
p=cell(7,1000);
for j=1:1000
p{1,j}=patient_condition(randi([1 numel(patient_condition)],1));
p{2,j}=test_type(randi([1 numel(test_type)],1));
p{3,j}=patient_origin(randi([1 numel(patient_origin)],1));
p{4,j}=doctor_orogin(randi([1 numel(doctor_orogin)],1));
p{5,j}=patient_age(randi([1 numel(patient_age)],1));
p{6,j}=insurance(randi([1 numel(insurance)],1));
p{7,j}=hospital(randi([1 numel(hospital)],1));
end
cell2mat(p)
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Random Number Generation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!