Borrar filtros
Borrar filtros

Append values of nested loop into matrix

1 visualización (últimos 30 días)
MadjeKoe
MadjeKoe el 14 de Jun. de 2022
Comentada: MadjeKoe el 15 de Jun. de 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

Respuestas (1)

David Hill
David Hill el 14 de Jun. de 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 comentarios
MadjeKoe
MadjeKoe el 15 de Jun. de 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 el 15 de Jun. de 2022
I updated my script and it does the job, except i cannot get it to loop every 120 trials

Iniciar sesión para comentar.

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