Borrar filtros
Borrar filtros

Simplifiing the MATLAB code

1 visualización (últimos 30 días)
Rene Sebena
Rene Sebena el 4 de Nov. de 2016
Comentada: Rene Sebena el 4 de Nov. de 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!

Respuesta aceptada

Image Analyst
Image Analyst el 4 de Nov. de 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 comentario
Rene Sebena
Rene Sebena el 4 de Nov. de 2016
Thank you, this helped a lot!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by