How to substitute some of the values in a matrix

1 回表示 (過去 30 日間)
Elaheh
Elaheh 2018 年 7 月 12 日
回答済み: dpb 2018 年 7 月 12 日
Hello all I have a matrix (748*6 double) including numbers and NaNs. The first column is test item numbers (defined already as ID) such as 1,3,5,7, etc, and the fourth column is the reaction times of participants (defined already as RT; 678, 467, etc). I need to replace some of the reaction times in this matrix. The new reaction times are in another matrix (defined already as RTc, 144*1 double) and I have the item numbers too (defined already as IDwords , 144*1 double). I wrote this code so that the reaction times in the old matrix would be substituted by the new reaction times. However, it does not work. I appreciate your help.
r=0;
for i=1:size(ID,1)
for ii=1:size(ID,2)
if ID(i,ii)==IDwords;
RT(i,ii)=RTc;
r=r+1;
end
end
end

採用された回答

dpb
dpb 2018 年 7 月 12 日
for i=1:size(ID,1)
[inA,locB]=ismember(ID(i),IDwords);
if inA
RT(inA)=RTc(locB);
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by