For loop index problem

조회 수: 8 (최근 30일)
Lydia Brown
Lydia Brown 2017년 10월 27일
편집: KL 2017년 11월 2일
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
Roman Müller-Hainbach
Roman Müller-Hainbach 2017년 11월 2일
Where is your definition of sortresultfunction?

댓글을 달려면 로그인하십시오.

답변 (1개)

KL
KL 2017년 11월 2일
편집: KL 2017년 11월 2일
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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by