0

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

2
  • It is not clear: are you expecting an array with labels [1 2 3] with the amount of each label is distributed with a different mean and variance? Commented Dec 22, 2014 at 10:53
  • Yes, I expect an array in output with a sequence of labels ordered by the action and distributed with the different mean and variance that I have indicate as parameter in the array of actions..For example the array "ACTIVITY_WAKE' could start with 1111111111 (for 300 time +/-60), after 3333333 (30 times +/-10) and finally 2222222 (120 times +-15) Commented Dec 22, 2014 at 10:59

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Are you sure about the formula to obtain n? Because I obtain always values near the mean value, with little variance...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.