Coding Time
      Hidden Commander @hiddencommander
        
          started
        
        Coding Time
    
    Hidden Commander @hiddencommander
    function [upstroke, duration] = apdAndCl(optical)
%using the sgolay to find the kernals for the first and second
%differentiation
[b,g] = sgolay(2,51);
k1 = g(:,2);
k2 = g(:,3);
%find the convolution using these kernals
d31a = conv(optical, flip(k1),'same'); 
d31b = conv(optical, flip(k2),'same');
%finding the peaks from this data
peaks1 = find(getPeaks(d31a, 140)); 
peaks2 = find(getPeaks(d31b, 80));
upstroke = mean(diff(peaks1)); 
depo = peaks1*0;
for i = 1:length(peaks1)
    nextpeakinPeaks2 = find(peaks2>peaks1(i)); % the first element of nextpeakinPeaks2 is the indixe you need to find depolarization point in Peaks2
    depo(i)=peaks2(nextpeakinPeaks2(1)); % Therefore you have nextPeak(1), it tells you which element in depo is the end of action potential 
end
% To find mean duration, find the difference between the start and end of
% an action potential 
duration = mean(depo - peaks1)/.75;
t = (0:length(optical)-1) / .75;
plot(t, optical,'b');
hold on
plot(peaks1/.75,optical(peaks1),'ro')
plot(depo/.75,optical(depo),'rx')
  
      Sobo275 @sobo275
        
          commented on
        
        Coding Time
    
    Sobo275 @sobo275
    Alright so I’m no coding magician but I know there’s a troubleshooting step like this. Explain to me what this code does and why it’s coded the way it does. If you do that I’m sure you’ll find that you made a simple error. 
  Please login to post.
