function [membranPotAVG]=avgPerFrameNatMovies ... (membranePot,ttls_ms,MovieFrames,Hz) %function [membranPotAVG]=avgPerFrameNatMovies ... % (membranePot,ttls_ms,MovieFrames,Hz) %builds the average membrane potential between frames for the natural movie % INPUT: membranePos -> membrane Potential % ttls_ms -> pulses in ms % MovieFrames -> number of frames per movie % Hz -> update rate in excel file % % OUTPUT: membranPotAVG -> average membrane potential per frames %make the average membrane potential between two stimulus frames membranPotAVG=zeros(MovieFrames,size(ttls_ms,2)); for jj=1:size(ttls_ms,2) %nbr of trials for kk=1:size(ttls_ms,1) % nbr of frames if kk==size(ttls_ms,1) %for the last frame membranPotAVG(kk,jj)=mean(membranePot(ttls_ms(kk,jj) ... :ttls_ms(kk,jj)+floor(1000/Hz)-1)); %because you dont have the pulse for when the frame ends, take the 40ms after the last frame to include the response to that frame. else membranPotAVG(kk,jj)=mean(membranePot(ttls_ms(kk,jj) ... :(ttls_ms(kk+1,jj)-1))); %detail: -1ms because the next ms is already the start of the new stimulus frame end end end end