1

I have the following lines of code where I find an event "41" in my cell array called Events (minimal example of this array included below) and the lines of code allow me to add 8 events labeled "411" after "41" and this is output in out1 (a result of this is shown as well). My issue is that I need to include 5 entries of "411" BEFORE "41" and I'm not sure how to do it.

How can I modify the lines below to be able to do that easily?

out1 = arrayfun( @(x,b) [x; repmat({'411'}, 8*b, 1)], Events, strcmp('41',Events), 'uni', 0 );
out1 = vertcat(out1{:});
Events = ['9991'    '9991'  '9991'  '9991'  '9991'  '9991'  '9992'  '10'    '11'    '41'    '42'    '10'    '11'    '43'    '44'];

out1 = ['9991'  '9991'  '9991'  '9991'  '9991'  '9991'  '9992'  '10'    '11'    '41' '411' '411'  '411' '411' '411' '411' '411' '411'   '42'    '10'    '11'    '43'    '44'];

Thanks!

1 Answer 1

1

In order to help, could you be more specific to define the issue? Will the array “Events” always be single dimension? Do you expect that “41” will appear only once or multiple times?

I have no way to test it right now but I guess this should do it:

out1 = arrayfun( @(x,b) [repmat({'411'}, 5*b, 1), x], Events, strcmp('41',Events), 'uni', 0 ); out1 = vertcat(out1{:});

Let me know if you still have trouble with it and I can have a more in depth look this evening

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

2 Comments

41 will appear multiple times (here it's only appearing once because I'm giving a minimal example). And yes it will be a single dimension. Essentially I want to add 5 x "411"s before 41 just as I am adding 8 x "411"s after it...
Super. Great to hear it helped!

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.