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
madhan ravi
madhan ravi 2018 年 11 月 28 日
Anytime :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by