get NEURON data from MATLAB

Moderator: wwlytton

ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: get NEURON data from MATLAB

Post by ted »

nasrin.sh wrote:I put my .hoc file in this path:
C:\nrn70\bin
. . .

Code: Select all

result =

/cygdrive/c/Users/Nasrin/Documents/MATLAB/
and my Matlab file is here:

Code: Select all

c/Users/Nasrin/Documents/MATLAB/
Well, there's the cause of your problem. The current working directory is
c/Users/Nasrin/Documents/MATLAB/
but your hoc file is somewhere else, so NEURON can't find it.

By the way, it's a very bad idea to put files inside NEURON's installation tree. Don't do it. It risks breaking things. There's a reason why MSWin, by default, hides system files and prevents you from putting your own stuff inside places like c:\windows or c:\win32. So get your hoc, ses, mod, dat, and txt files out of c:\nrnxx and keep them out of there.
nasrin.sh
Posts: 18
Joined: Mon Sep 20, 2010 10:28 pm
Location: Iran

Re: get NEURON data from MATLAB

Post by nasrin.sh »

I put Matlab file and hoc file both in the same path
c/Users/Nasrin/Documents/MATLAB
and also set the working directory to this path
c/Users/Nasrin/Documents/MATLAB/
but I don't know why it doesn't work,shouldn't I mention the name of my hoc file in matlab code?
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: get NEURON data from MATLAB

Post by ted »

nasrin.sh wrote:shouldn't I mention the name of my hoc file in matlab code?
Yes, if you want your Matlab program to launch NEURON. Basically, you want Matlab to execute a loop like this (written in pseudocode):

Code: Select all

REPEAT
  write some parameters to a data file
  launch NEURON, making it read a hoc file
  optional: read the results that NEURON wrote, then decide what to do next
UNTIL done
Your NEURON hoc file has to read the parameters from the data file, run a simulation, print results to a file, then exit.
nasrin.sh
Posts: 18
Joined: Mon Sep 20, 2010 10:28 pm
Location: Iran

Re: get NEURON data from MATLAB

Post by nasrin.sh »

I explain what I think I did ,please tell me if it is wrong

Code: Select all

save MyDataP.dat p -ascii
save MyDataW.dat w -ascii
save MyDataN.dat n -ascii
I use these code to write parameters to data files,

Code: Select all

[status,result]=system('C:\nrn70\bin\nrniv.exe -nobanner -c "print getcwd()" -c "quit()"')
and I use the code above to launch Neuron.

Code: Select all

f1.ropen("MyDataN.dat")
nSThcells = f1.scanvar()
...
and use the code above to use the data in neuron.thanks a lot.
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: get NEURON data from MATLAB

Post by ted »

nasrin.sh wrote:

Code: Select all

[status,result]=system('C:\nrn70\bin\nrniv.exe -nobanner -c "print getcwd()" -c "quit()"')
and I use the code above to launch Neuron.
[status,result]=system('C:\nrn70\bin\nrniv.exe -nobanner -c "print getcwd()" -c "quit()"')
is a Matlab statement that uses Matlab's system() function to pass a command string to your operating system. In this particular case, the command string is

Code: Select all

C:\nrn70\bin\nrniv.exe -nobanner -c "print getcwd()" -c "quit()"
which merely starts NEURON and tells NEURON to print the path of the current working directory, then exit.

But you want NEURON to start and read a particular hoc file. If the name of your hoc file is MainFun.hoc, then you probably want your operating system to execute this command string:

Code: Select all

C:\nrn70\bin\nrniv.exe -nobanner MainFun.hoc
If that is correct, then you want to change the line in your Matlab program to

Code: Select all

[status,result]=system('C:\nrn70\bin\nrniv.exe -nobanner MainFun.hoc')
nasrin.sh
Posts: 18
Joined: Mon Sep 20, 2010 10:28 pm
Location: Iran

Re: get NEURON data from MATLAB

Post by nasrin.sh »

thank u so much,it works.
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: get NEURON data from MATLAB

Post by ted »

Good!
nasrin.sh
Posts: 18
Joined: Mon Sep 20, 2010 10:28 pm
Location: Iran

Re: get NEURON data from MATLAB

Post by nasrin.sh »

Hi.I'm really sorry that I waste your time with my questions,I have another question also I want to save the voltages of every neurons on the network in NEURON software and give it back to Matlab.would you tell me how can I access the votlages of neurons and save it to send it to Matlab.?...
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: get NEURON data from MATLAB

Post by ted »

You'll have to record the membrane potentials to Vectors and write them to one or more output files after the end of the simulation. You'll find the Vector class and its record() method described in the Programmer's Reference. First try capturing the time course of just one cell to make sure that things are working correctly. Then add the rest of them.
nasrin.sh
Posts: 18
Joined: Mon Sep 20, 2010 10:28 pm
Location: Iran

Re: get NEURON data from MATLAB

Post by nasrin.sh »

may you introduce me a sample which do this?
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: get NEURON data from MATLAB

Post by ted »

There is an example in the Programmer's Reference documentation of the Vector class's record() method. Go to http://www.neuron.yale.edu, click on Programmer's Reference, then select "Quick Index" and click on Vector.

If your cells are instances of object classes, their sections should be accessible from hoc by this syntax
cellname.sectionname
So if you had an objref called pyr that pointed to an instance of a cell class (that is, your network setup code contained statements something like these

Code: Select all

objref pyr
pyr = new SomeCellClass()
) then to record the membrane potential of pyr.soma you would use statements like this:

Code: Select all

// execute these statements _after_ the network has been set up
// only need to do this once--a new recording will be generated on each run
objref vvec
vvec = new Vector()
vvec.record(&pyr.soma.v(0.5))
You'll probably also want to record time to a vector

Code: Select all

objref tvec
tvec = new Vector()
tvec.record(&t)
After you get it working with just one voltage and one time vector, you'll want to record voltage time course from many cells. For this it is best to use a List to manage all of your Vectors. Assuming that each cell in your network has been appended to a List, you can iterate over each cell in the list of cells, creating a Vector to capture the time course of its somatic v, executing a Vector record() statement, and finally appending the Vector to the List of Vectors. Your program will be organized like this (writing in pseudocode):

Code: Select all

read parameters from the textfile that Matlab wrote
specify properties of cell classes
create instances of cell classes (and append them to a List of cells)
connect the cells (and append the NetCons to a List of connections)
// at this point the network has been created
// now set up recording
create a Vector called tvec and use the record() method to make it capture t
for each element in the List of cells {
  create a new Vector and use the record() method to make it capture this cell's soma.v(0.5)
  append the Vector to the list of recording Vectors
}
run a simulation
open a new output file
write tvec to the output file
for each element in the list of recording Vectors {
  write this vector to the output file
}
close the output file
nasrin.sh
Posts: 18
Joined: Mon Sep 20, 2010 10:28 pm
Location: Iran

Re: get NEURON data from MATLAB

Post by nasrin.sh »

I use this code as you said but it has a syntax error on this line

Code: Select all

vvec = new Vector()
I think may be it can't identify the class of vector..!
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: get NEURON data from MATLAB

Post by ted »

What is the error message?
nasrin.sh
Posts: 18
Joined: Mon Sep 20, 2010 10:28 pm
Location: Iran

Re: get NEURON data from MATLAB

Post by nasrin.sh »

SORRY,I found my mistake,I had not used a list!;)
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: get NEURON data from MATLAB

Post by ted »

It's always good when one discovers one's own mistake.
Post Reply