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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by