Simplifiing the MATLAB code

1 vue (au cours des 30 derniers jours)
Rene Sebena
Rene Sebena le 4 Nov 2016
Commenté : Rene Sebena le 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!

Réponse acceptée

Image Analyst
Image Analyst le 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 commentaire
Rene Sebena
Rene Sebena le 4 Nov 2016
Thank you, this helped a lot!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by