Reputation: 41
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
Upvotes: 0
Views: 74
Reputation: 114866
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
.
Upvotes: 1