How do I stop overwriting in this "for" loop
2 views (last 30 days)
Show older comments
I am trying to create a new datastructure call temp_All_2 from the for loops above. I can create the new data structure but for each participant it overwrites. How can I get the data to not overwrite?
temp_FixOn = FixOn;
% for tt = 1:length(trials)
% trfix(tt,:) = nanmean(temp_FixOn(temp_FixOn(:,TRIAL_INDEX)==trials(tt), pupsize));
%
% %trfix(tt,1:length(fix_pup(unique(FixOn(:,TRIAL_INDEX)==trials(tt))))) = fix_pup(FixOn(:,TRIAL_INDEX)==trials(tt));
%
% %create means for constants becuase i'm too dumb to figure out
% %another way.
%
% trTrial(tt,:) = nanmedian(temp_FixOn(temp_FixOn(:,TRIAL_INDEX)==trials(tt), TRIAL_INDEX));
% trBLOCK(tt,:) = nanmedian(temp_FixOn(temp_FixOn(:,TRIAL_INDEX)==trials(tt), BLOCK));
% trCOMP(tt,:) = nanmedian(temp_FixOn(temp_FixOn(:,TRIAL_INDEX)==trials(tt), COMP));
% trLINE(tt,:) = nanmedian(temp_FixOn(temp_FixOn(:,TRIAL_INDEX)==trials(tt), LINE));
% trRESP(tt,:) = nanmedian(temp_FixOn(temp_FixOn(:,TRIAL_INDEX)==trials(tt), RESP));
%
%
% end
%
% temp_CueOn = CueOn;
% for tt = 1:length(trials)
% trCueOn(tt,:) = nanmean(temp_CueOn(temp_CueOn(:,TRIAL_INDEX)==trials(tt), pupsize));
% end
%
% temp_CTI = CTI;
% for tt = 1:length(trials)
% trCTI(tt,:) = nanmean(temp_CTI(temp_CTI(:,TRIAL_INDEX)==trials(tt), pupsize));
% end
%
% temp_TargOn = TargOn;
% for tt = 1:length(trials)
% trTargOn(tt,:) = nanmean(temp_TargOn(temp_TargOn(:,TRIAL_INDEX)==trials(tt), pupsize));
% end
%
% temp_RespMade = RespMade;
% for tt = 1:length(trials)
% trRespMade(tt,:) = nanmean(temp_RespMade(temp_RespMade(:,TRIAL_INDEX)==trials(tt), pupsize));
% end
%
% temp_RespWind = RespWind;
% for tt = 1:length(trials)
% trRespWind(tt,:) = nanmean(temp_RespWind(temp_RespWind(:,TRIAL_INDEX)==trials(tt), pupsize));
% end
%
%
%
% temp_All_2 = [trTrial, trBLOCK, trCOMP, trLINE, trRESP, trfix, trCueOn, trCTI, trTargOn, trRespMade, trRespWind]
%
%
%
%
% end
1 Comment
dpb
on 13 Oct 2022
You indexed all the intermediate variables, but then put the compendium of them all inside another loop -- you're doing all the inner loops over and over and over ... length(trials) times. Once each should be sufficient. :)
It's not clear what you want the results to be and we don't have any data to work with to try...
Attach a (relatively small) dataset (as a .mat file) would be fine and then explain what results you're trying to get.
It looks like grouping variables might be very useful here to compute a bunch of different statistics/results over an input set of data by some other variable values.
If we knew what those were, probably could vectorize the whole thing, "the MATLAB way..."
Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!