How do I stop overwriting in this "for" loop

조회 수: 7 (최근 30일)
Joe Opdenaker
Joe Opdenaker 2022년 10월 13일
댓글: dpb 2022년 10월 13일
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
dpb
dpb 2022년 10월 13일
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..."

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by