-4

I have a model of a neuron firing. There are many variables in c code, but the one I am interested in is voltage. I want to keep track of how long the neuron fires and once the neuron reaches a certain value (here -20 mV) it will definitely fire. I've attached a picture - I want to keep track of the green parts especially. I'm guessing you use the time fxn but I'm not sure how? enter image description here

x[i] represents voltage. This is the equation for dx[i]

 dx[i]=ab*(-(ina(frt,v[i],n[i],nae[i],nai[i])+inap(frt,v[i],hp[i],nae[i],nai[i])+ik(frt,v[i],n[i],ke[i],ki[i])+ipump[i]+il(v[i])+inmda(inanmda,iknmda,icanmda)+icapump)+iapp); //v
dbush
  • 205,898
  • 23
  • 218
  • 273
soscrewed
  • 1
  • 2
  • 1
    As I am not into "*firing neurons*" ;-): would a resolution in seconds do? – alk Dec 05 '16 at 19:23
  • Yes seconds is good. - I need to find the time difference when the neuron voltage first increases and reaches -20 mV and then eventually it decreases and reaches -20 mV – soscrewed Dec 05 '16 at 19:25
  • 1
    The question seems ambiguous to me. Do you want to *"measure the time a part of your code runs for"* or *"compute time using physical formulas"*? – HolyBlackCat Dec 05 '16 at 19:35

1 Answers1

1

Try this:

int t1 = time(0);
fire_neuron();     // place the "neuron firing" code here
int t2 = time(0);

printf("Seconds taken to fire neuron: %d\n", t2 - t1);

If you want to do it "properly", you can #include <time.h> and write it like this:

time_t t1 = time(NULL);
fire_neuron();            // place the "neuron firing" code here
time_t t2 = time(NULL);

printf("Seconds taken to fire neuron: %f\n", difftime(t2, t1));

As I can't see your code, I don't know exactly how to help you. Maybe you want something like...

if (dx[i] <= -20) {
    time_t t1 = time(NULL);
    fire_neuron();
    time_t t2 = time(NULL);
}

printf("Seconds taken to fire neuron: %f\n", difftime(t2, t1));
MD XF
  • 7,860
  • 7
  • 40
  • 71
  • `int` should really be `time_t`. – alk Dec 05 '16 at 19:19
  • 1
    And `... %d\n", t2 - t1);` should be `... %f\n", difftime(t2, t1));` – alk Dec 05 '16 at 19:20
  • @alk Yes, yes, but [technically](http://stackoverflow.com/questions/471248/what-is-ultimately-a-time-t-typedef-to), `time_t` is a `typedef` for `signed int`. – MD XF Dec 05 '16 at 19:22
  • how do i write in terms of the time interval being when the voltage first reaches -20 and then when it goes down to -20 ? – soscrewed Dec 05 '16 at 19:23
  • @soscrewed I have no idea; you'd need to show us your code. But first, see [How to create a Minimal, Complete, and Verifiable Example](/help/mcve). – MD XF Dec 05 '16 at 19:24
  • 1
    @MDXF: Since around the year 2000, on many system it's a `long`, will say wider then 32 bits. – alk Dec 05 '16 at 19:24
  • 1
    @soscrewed you have provided no code to indicate how you are going to get those values, so how are we supposed to know? – Fantastic Mr Fox Dec 05 '16 at 19:24
  • Sorry I would post the whole code but its too long. x[i] represents the voltage of the neuron, dx[i] is the rate of change of voltage dx[i]=ab*(-(ina(frt,v[i],n[i],nae[i],nai[i])+inap(frt,v[i],hp[i],nae[i],nai[i])+ik(frt,v[i],n[i],ke[i],ki[i])+ipump[i]+il(v[i])+inmda(inanmda,iknmda,icanmda)+icapump)+iapp); //v – soscrewed Dec 05 '16 at 19:45