code I am using is as follows:
for i=1:length(Rpeaks) %starts at first peak which is first whole step
%if i==1
if Rpeaks(i)-halfsegment<0 window=(1:Rpeaks(i)+halfsegment); %takes into account that the forces don't start a full halfsegment prior to first valley
step=GRFright(window); %assign the step the actual data values
normstep=(step./max(step)); %normalize the step
toeoff=find(normstep < min(normstep)+.05 , 1); RTO(n)=toeoff+window(1); heelstrike=find(normstep(toeoff:end) > min(normstep)+.05 , 1);% 1st zero location; syntax of ,1 returns first satisfying value
RHS(n)=heelstrike+toeoff+window(1); elseif Rpeaks(i)+halfsegment>length(GRFright) window=(Rpeaks(i)-halfsegment:size(GRFright)); step=GRFright(window); %assign the step the actual data values normstep=(step./max(step)); %normalize the step toeoff=find(normstep < min(normstep)+.05 , 1); RTO(n)=toeoff+window(1); heelstrike=find(normstep(toeoff:end) > min(normstep)+.05 , 1);% 1st zero location; syntax of ,1 returns first satisfying value RHS(n)=heelstrike+toeoff+window(1); else window=(Rpeaks(i)-halfsegment:Rpeaks(i)+halfsegment); %find window of frames-100 added to catch full end of step
step=GRFright(window); %assign the step the actual data values normstep=(step./max(step)); %normalize the step toeoff=find(normstep < min(normstep)+.05 , 1); RTO(n)=toeoff+window(1); heelstrike=find(normstep(toeoff:end) > min(normstep)+.05 , 1);% 1st zero location; syntax of ,1 returns first satisfying value RHS(n)=heelstrike+toeoff+window(1); n=n+1; endend
within the for loop I have the same lines written three times after the "If statement" defining what the window should be. Is there a way to shorten the code so I only have to make one change for each condition when necessary? Thanks in advance.
Best Answer