For loop overwriting data
Mostrar comentarios más antiguos
Hello,
I have this code below:
clear all;
names= {'AB_Clean','AK_Clean'};
data=[];
for iSubj=1:numel(names)
filetoload= names{iSubj};
t = readtable([filetoload '.xls']);
data.id = num2str (iSubj);
response = mod(t.MouseClickAngleToCenter,180);
condition = mod(t.Condition,180);
target = mod(t.CenterPackmanOriantation,180);
for i=1:length(response)
A=str2num(t.SurroundingPackmansRotations_tl_bl_tr_br_{i});
if ~isempty(A)
distractors_local(i,:) = mod(A,180);
else
distractors_local(i,:) = [nan nan nan nan];
end
end
distractors_global = mod(t.PackmansRectangleRotation+90,180); %Original analysis
%distractors_global = mod(t.PackmansRectangleRotation,180);%New collinearity analysis
errors = circdist(response,target);
errors(errors>90) = errors(errors>90) -180;
errors(errors<-90) = errors(errors<-90) +180;
distractors1 = circdist(distractors_global,target);
distractors4 = circdist(distractors_local,target);
distractors1(distractors1>90) = distractors1(distractors1>90) -180;
distractors1(distractors1<-90) = distractors1(distractors1<-90) +180;
distractors4(distractors4>90) = distractors4(distractors4>90) -180;
distractors4(distractors4<-90) = distractors4(distractors4<-90) +180;
distractors4 = distractors4(:,1:2);
for c=unique(condition)'
data.errors = errors(condition==c)';
data.distractors = [distractors1(condition==c,:)'; distractors4(condition==c,[1 2])'];
end
end
I want the loop to go through the data of each participant (i.e AB_Clean and AK_Clean) and save the data.errors, data.distractors and data.id variables for each participant in the "data" struct. There is something missing in my code, since the variables are being overwritten every time the loop starts. Any help with this would be very much appreciated.
Thanks!
-Mikel
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!