-2

i'm wondering oif someone can help, im trying to work through the following book:

Cohen, Mike X. MATLAB for Brain and Cognitive Scientists (MIT Press) (Page 490). The MIT Press. Kindle Edition.

This is a exact cut and paste of the code example given for modelling a simple intergrate and fire nueron, however everytime I run it I get a undefined error :(, from previous knowledge I know that usually undefined relates to calling a function which has not been explicitly declared. Problem is, i have no idea what either 'ti' or 'timevec' are supposed to relate to? (ive tried switching them to variable I have already declared, eg, 'time', but that just caused more issues!) Perhaps it's a syntax change that i've missed and quick fix? im using R2017b on OSX.

Thanks!

volt_rest = -70; % resting potential (mV) 
volt_thresh = -50; % action potential thresh. (mV) 
volt_reset = -75; % post-spike reset voltage 

% membrane parameters 
R_m = 10; % neuron membrane resistance (MOhm)
 tau = 10; % time constant of decay (ms)

srate = 10000; % sampling rate in Hz 
sim_dur = 1; % stimulus duration in seconds 
time = 0:1/srate:sim_dur - 1/srate; 
input = zeros(1,length(time));
 input(dsearchn(time',.3):dsearchn(time',.7)) = 3;

neuronV = volt_rest + zeros(size(timevec));
spiketimes = [];

if neuronV(ti) > volt_thresh 
neuronV(ti) = volt_reset; 
spiketimes = cat(1,spiketimes,ti); 
end

r_i = volt_rest + input(ti)*R_m; 
neuronV(ti+1) = r_i + (neuronV(ti) - r_i) * exp(-1000/srate/tau);

neuronV(neuronV==volt_reset) = 40;
MJV_2017
  • 25
  • 7
  • Looks like timevec is not assigned before being used – Justas Mar 01 '18 at 17:07
  • you're right, it hasn't, the problem is I have no idea what 'timevec' relates to? Is it a function which has since been depracted/renamed? – MJV_2017 Mar 01 '18 at 21:22
  • Since I didn't write the original code, I don't know for sure, but it looks like it's a vector/array whose size is equal to the number of time-steps in the simulation, e.g array with srate*sim_dur elements – Justas Mar 04 '18 at 23:45
  • 3
    I'm voting to close this question as off-topic because this question should've been directed to the author of the book, as they should clarify it. – Adriaan Apr 08 '18 at 18:31

1 Answers1

4

I'm the author of that book. I'm sorry you got confused about the code. The book itself contains only the most pertinent lines, and the online code (available from mikexcohen.com) contains all the code. Those variables are clearly defined in the online code, for example timevec is defined on line 17 of chapter30.m. If I included every single line of code in the book it would have been twice as long, cost much more, and for no good reason. I thought I stated this fact pretty clearly in the beginning of the book. It's also on my website and on the MIT Press website. The best way to learn from the book is to download the code and go through that code on your computer while reading. This also has the benefit of saving you time to copy code from the book into MATLAB.

In the future, if you have questions or issues, please email me directly, or you can leave a public comment by posting on the google-groups forum for my books. Or email me to let me know that you posted a question here. I usually respond to emails and posts within a day, and we could have resolved your confusion a long time ago. Perhaps reading the beginning of the book or contacting me directly could have prevented your negative review on amazon.co.uk.

Zoe
  • 27,060
  • 21
  • 118
  • 148