generating random for j elemnts in matrix from set of data i have

조회 수: 1 (최근 30일)
Kamal Ebrahimi
Kamal Ebrahimi 2018년 11월 28일
댓글: madhan ravi 2018년 11월 28일
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

채택된 답변

madhan ravi
madhan ravi 2018년 11월 28일
편집: madhan ravi 2018년 11월 28일
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
Kamal Ebrahimi
Kamal Ebrahimi 2018년 11월 28일
Yes exactly this was what i'm looking for,thank you so much and god bless you

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by