Simplifiing the MATLAB code

1 view (last 30 days)
Rene Sebena
Rene Sebena on 4 Nov 2016
Commented: Rene Sebena on 4 Nov 2016
Hi there, I know this is something simple, but I am quite new in matlab and will aprreciate your help with this issue,
I know order of specific events in one dimension matrix:
e1 = [1,19,24]; % order of specific condition in matrix;
e2 = [2,8,27];
e3 = [4,16,23];
I have data with the same event type and I need to change event.type based on information above, so that:
EEG.event(1,1).type = 1;EEG.event(1,19).type = 1;EEG.event(1,24).type = 1;
EEG.event(1,2).type = 2;EEG.event(1,8).type = 2;EEG.event(1,27).type = 2;
EEG.event(1,4).type = 3;EEG.event(1,16).type = 3;EEG.event(1,23).type = 3;
How can I do it in simple way?
Thank you very much for your time and help!

Accepted Answer

Image Analyst
Image Analyst on 4 Nov 2016
Would you like a for loop? This could be simpler if the e vectors were much long than 3 elements
for k = 1 : length(e1)
EEG.event(1,e1(k)).type = 1;
EEG.event(1,e2(k)).type = 2;
EEG.event(1,e3(k)).type = 3;
end
If e1, e2, and e3 don't all have the same length then you're best off using 3 separate for loops.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!