# Simplifiing the MATLAB code

4 Ansichten (letzte 30 Tage)
Rene Sebena am 4 Nov. 2016
Kommentiert: Rene Sebena am 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!
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Image Analyst am 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.
##### 1 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Rene Sebena am 4 Nov. 2016
Thank you, this helped a lot!

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by