Append values of nested loop into matrix

3 vues (au cours des 30 derniers jours)
MadjeKoe
MadjeKoe le 14 Juin 2022
Commenté : MadjeKoe le 15 Juin 2022
Hi guys, I am trying to make a nested loop work and append the values to a existing matrix. I have 28 participants (who have numbers varying from 1 - 56), that each performed 5 blocks of 120 trials. For each individual block, I want to accumulate the correct responses (resp_jong == 1) at each trial (so up until the 120th trial) and append it 1 column & I want another column where I accumulate the trial that were responded to (resp_jong == -1 | resp_jong == 1). I have been working on the script all day, but I am completely lost and cannot get it to work at all. Does there happen to be anyone that can help me out a little bit? Thank you very very much in advance
r=readmatrix('data_jong_edit.txt');
r(isnan(r(:,1)),:)=[];
empty = nan(16560,2);
r = [r empty];
% M(end+1,:) = NaN;
% corrects = [];
% responses = [];
count1 = 0;
count2 = 0;
re = r(:,9);
for k=1:length(tr)
if re(k,:) == 1
count1 = count1 + 1;
count2 = count2 + 1;
cor(k,:) = count1;
res(k,:) = count2;
elseif re(k,:) == -1
count1 = count1;
count2 = count2 + 1;
cor(k,:) = count1;
res(k,:) = count2;
elseif re(k,:) == 9999
count1 = count1;
count2 = count2;
cor(k,:) = count1;
res(k,:) = count2;
end
end

Réponses (1)

David Hill
David Hill le 14 Juin 2022
r=readmatrix('data_jong_edit.txt');
r(isnan(r(:,1)),:)=[];
u=unique(r(:,1));
for k=1:length(u)
re=r(r(:,1)==u(k),:);
re=re';
try
rs=reshape(re,11,120,[]);
s1(:,k)=squeeze(sum(rs(9,:,:)==1));%number of 1 responses per block
s2(:,k)=squeeze(sum(rs(9,:,:)==-1));%number of -1 responses per block (s1+s2 is number of 1 and -1)
catch
continue;
end
end
  2 commentaires
MadjeKoe
MadjeKoe le 15 Juin 2022
Thank you so much for your help!! I actually meant to store the values for each single trial, do you maybe happen to know how I can store these so that the total score is displayed at the moment of the trial? See the picture for an example.
MadjeKoe
MadjeKoe le 15 Juin 2022
I updated my script and it does the job, except i cannot get it to loop every 120 trials

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by