简体   繁体   中英

Generate array with 3 gaussian distributions MATLAB

I need help! My purpose is to develop in MATLAB a routine that, starting from a series of actions (modeled by a label, a mean value and a variance), is able to generate an array of activity. I explain better with my code:

action_awake_in_bed = [1 5*60 1*60];
action_out_of_bed = [3 30 10];
action_out_bedroom = [2 2*60 15];
ACTIVITY_WAKE = {'action_awake_in_bed','action_out_of_bed','action_out_bedroom'};

The first element of action array is a label (a posture label), the second element is the length of the action (in seconds), the third element the variance.

I need as output the array ACTIVITY_WAKE ....

Thanks

Let's use a struct to store the meta-parameters

action.awake_in_bed   = [1 5*60 1*60];
action.out_of_bad     = [3 30 10];
action.out_of_bedroom = [2 2*60 15];
ACTIVITY = {'awake_in_bed','out_of_bad','out_of_bedroom'};

After these pre-definitions, we can sample an activity vector

ACTIVITY_WAKE = cell(1,numel(ACTIVITY)); 
for ii = 1:numel( ACTIVITY ) %// foreach activity
    cp = action.(ACTIVITY{ii}); %// get parameters of current activity
    n = round( cp(2) + sqrt(cp(3))*randn() ); %// get the number of samples
    ACTIVITY_WAKE{ii} = repmat( cp(1), 1, n );
end
ACTIVITY_WAKE = [ ACTIVITY_WAKE{:} ];

To get the number of samples I use the following recipe to sample from a normal distribution with mean~=0 and std~=1 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM