For loop index problem

8 visualizaciones (últimos 30 días)
Lydia Brown
Lydia Brown el 27 de Oct. de 2017
Editada: KL el 2 de Nov. de 2017
I have 3 variables called all_data_sess1, all_data_sess2 and all_data_sess3 which each contain a 216x8 matrix. When I run the following part of code below, the values for these variables change to just 216 and the matrix is gone, which I don't want. There are 216 rows and I want my for loop to go through each row, which is why I used to loop index 1:length(RT) (I also tried 1:216 but I get the same problem). I ran the whole script line by line and found when it gets to the bit of code below, the value for all_data_sess1 (or 2 or 3) get set to 1, and each time it goes through the for loop, 1 is added every time, hence the end result is all_data_sess1 = 216. How do I make it look at each row and not change/overwrite the matrix assigned to the variable?
for all_data_sess1 = 1:length(RT) %debugger shows running this line adds 1 to all_data_sess1 each time through the loop, rather than using it as a loop index.
if RT <= 2 %Disregarding RTs longer than 2 seconds Should this cutoff be sooner? RT <= 1.5?
if performance == 1 %Disregarding incorrect trials Is this the right way to organise 2 conditions?? if RT <= 2 && if performance == 1?
sortresultfunction %variables don't change, this isn't working...?
end
end
end
Thanks for any help!
  1 comentario
Roman Müller-Hainbach
Roman Müller-Hainbach el 2 de Nov. de 2017
Where is your definition of sortresultfunction?

Iniciar sesión para comentar.

Respuestas (1)

KL
KL el 2 de Nov. de 2017
Editada: KL el 2 de Nov. de 2017
you have to use another variable name as iterator in your for loop
for k = 1:size(all_data_sess1,1)
%here use k to index all_data_sess1, for example,
something = all_data_sess1(k,1);
...
...
end

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