Input a vector to neuron
Input a vector to neuron
Hi Ted,
1. I am trying to input a vector which has two column, one is synaptic weight and one is delay time, to Neuron. This vector is created by Matlab and is saved as .txt file. However, I am not able to open it in Neuron. I also find that the vector with one column can be openned. What should I do with two-column vectors?
2. The second question is: when I change the synaptic weight and delay time of the model by loading the data from my above text file (assume that Neuron can read my two-column txt file), I will do the following syntax:
nclist.o(i).delay = vect.x.[1]
nclist.o(i).weight = vect.x[2]
Are these correct?
Thanks a lot!
1. I am trying to input a vector which has two column, one is synaptic weight and one is delay time, to Neuron. This vector is created by Matlab and is saved as .txt file. However, I am not able to open it in Neuron. I also find that the vector with one column can be openned. What should I do with two-column vectors?
2. The second question is: when I change the synaptic weight and delay time of the model by loading the data from my above text file (assume that Neuron can read my two-column txt file), I will do the following syntax:
nclist.o(i).delay = vect.x.[1]
nclist.o(i).weight = vect.x[2]
Are these correct?
Thanks a lot!
-
- Site Admin
- Posts: 6300
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Re: Input a vector to neuron
hoc can do the usual file text I/O. You'll want to read the Programmer's Reference documentation of ropen and fscan, or the File class's methods ropen and scanvar.Kim Ha wrote:I am trying to input a vector which has two column, one is synaptic weight and one is delay time, to Neuron. This vector is created by Matlab and is saved as .txt file.
Good question. This raises many issues.when I change the synaptic weight and delay time of the model by loading the data from my above text file (assume that Neuron can read my two-column txt file), I will do the following syntax:
nclist.o(i).delay = vect.x.[1]
nclist.o(i).weight = vect.x[2]
Are these correct?
First, hoc indices start with 0, not 1. Second, a Vector is a 1 dimensional array, so vecname.x[j] will generate an error message. It is possible to do this
Code: Select all
objref vecarray[2]
for i=0,1 vecarray[i]=new Vector()
Code: Select all
oc>for i=0,1 print vecarray[i]
Vector[5]
Vector[6]
Now I have a couple of questions for you.
Let's suppose that you change this
nclist.o(i).delay = vect.x[1]
nclist.o(i).weight = vect.x[2]
to this
nclist.o(i).delay = vect[0].x
nclist.o(i).weight = vect[1].x
which means that you have two vectors--vect[0] and vect[1]--where vect[0] contains the delays and vect[1] contains the corresponding weights, so setting up the weights and delays would use this loop:
Code: Select all
for i=0,nclist.count-1 {
nclist.o(i).delay = vect[0].x[i]
nclist.o(i).weight = vect[1].x[i]
}
Code: Select all
for i=0,nclist.count-1 {
nclist.o(i).delay = ncplist.o(i).x[0]
nclist.o(i).weight = ncplist.o(i).x[1]
}
DELAY = 0
WEIGHT = 1
so your code could look like this
Code: Select all
for i=0,nclist.count-1 {
nclist.o(i).delay = ncplist.o(i).x[DELAY]
nclist.o(i).weight = ncplist.o(i).x[WEIGHT]
}
Re: Input a vector to neuron
Thank you for your instruction.
I got your idea. Actually, I was working on the same thing as yours. I save delay and weigh to two text files and then scan them to neuron files. The code looks like the following:
The change of directory syntax also ensures my spike train file to be saved in the desired folder. Otherwise, the program will save it in C:/windows/system32. Opps! I do not know why.
I got the matlab-neuron interface work now.
Thank Ted for helping me understand many things!
I got your idea. Actually, I was working on the same thing as yours. I save delay and weigh to two text files and then scan them to neuron files. The code looks like the following:
Code: Select all
//Note to open ha.dat file need to change the directory to the position we save the file
getcwd()
chdir("C:/nrn73/lib/hoc")
load_file("ha.dat") //not sure we need this
objref n
n = new Vector()
objref f
f = new File()
f.ropen("ha.dat") //to read the txt file to a file of Neuron
n.scanf(f) // record to vector n
print n.size() //just to check
print n.x[1] //just to check
nclist.o(1).delay = n.x[1]
I got the matlab-neuron interface work now.
Thank Ted for helping me understand many things!
-
- Site Admin
- Posts: 6300
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Re: Input a vector to neuron
This
chdir("C:/nrn73/lib/hoc")
tells me you're writing into NEURON's installation tree. That's a bad idea, because
(1) if you make a mistake, you might overwrite or delete one of the files that NEURON depends on,
and
(2) if you ever install a new version of NEURON, the first thing you have to do is uninstall the previous version, and this means you will have to delete the old installation tree--and that will eliminate your own files.
It's best to put your own code in a directory that belongs to you. You might want to create such a directory in your own Documents folder, for example
C:\Users\ted\Documents\models
or perhaps in your Desktop folder
C:\Users\ted\Documents\models
Then each modeling project should have its own directory inside your models folder.
Thanks for using NEURON!
chdir("C:/nrn73/lib/hoc")
tells me you're writing into NEURON's installation tree. That's a bad idea, because
(1) if you make a mistake, you might overwrite or delete one of the files that NEURON depends on,
and
(2) if you ever install a new version of NEURON, the first thing you have to do is uninstall the previous version, and this means you will have to delete the old installation tree--and that will eliminate your own files.
It's best to put your own code in a directory that belongs to you. You might want to create such a directory in your own Documents folder, for example
C:\Users\ted\Documents\models
or perhaps in your Desktop folder
C:\Users\ted\Documents\models
Then each modeling project should have its own directory inside your models folder.
When I installed NEURON on my desktop pc, the installation directory turned out to be C:\, and that is also NEURON's working directory if I start NEURON by clicking on the nrngui icon in the NEURON program group. Of course, Windows prevents me from saving any ses files or writing any data files to C:\. But if I put a hoc file in a folder where I have write privileges, then double click on that file (inside Windows Explorer), NEURON starts with that folder as its working directory and I can write ses or data files there without difficulty.The change of directory syntax also ensures my spike train file to be saved in the desired folder. Otherwise, the program will save it in C:/windows/system32.
Thanks for using NEURON!
Re: Input a vector to neuron
Ted,
I have tried saving all files in a folder. In my init_fishmodel.hoc I have:
But the program cannot find fishmodel.hoc, initrun_fishmodel.hoc and wtdel.hoc. Therefore, I have to wirte the following:
Maybe, it is just the problem of my computer. Because at first the directory is C:/, now it is always C:/windows/system32.
I have tried saving all files in a folder. In my init_fishmodel.hoc I have:
Code: Select all
load_file("nrngui.hoc")
load_file("fishmodel.hoc")
load_file("initrun_fishmodel.hoc")
load_file("wtdel.hoc")
Code: Select all
load_file("nrngui.hoc")
chdir("C:/Users/Ha Ngo/My Documents/Models/twosegments")
load_file("fishmodel.hoc")
load_file("initrun_fishmodel.hoc")
load_file("wtdel.hoc")
-
- Site Admin
- Posts: 6300
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Re: Input a vector to neuron
Please run these tests.
1. Create a text file called test.hoc that contains this statement
system("pwd")
and save it to your Desktop. Then double click on test.hoc and tell me what NEURON prints to its terminal.
2. Create a folder on your desktop called newtest.
In that folder put the following two files:
main.hoc which containsand sub.hoc which contains
Now double click on main.hoc and tell me what NEURON prints to its terminal.
1. Create a text file called test.hoc that contains this statement
system("pwd")
and save it to your Desktop. Then double click on test.hoc and tell me what NEURON prints to its terminal.
2. Create a folder on your desktop called newtest.
In that folder put the following two files:
main.hoc which contains
Code: Select all
print "in main, about to load sub.hoc"
load_file("sub.hoc")
print "back in main"
Code: Select all
print "in sub"
Re: Input a vector to neuron
Ted,
For the first test, the following appears:
For the second test, the command window prints the following:
For the first test, the following appears:
Code: Select all
NEURON -- Release 7.3 (849:5be3d097b917) 2013-04-11
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2013
See http://www.neuron.yale.edu/neuron/credits
/cygdrive/c/Windows/system32
0
oc>
Code: Select all
NEURON -- Release 7.3 (849:5be3d097b917) 2013-04-11
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2013
See http://www.neuron.yale.edu/neuron/credits
in main, about to load sub.hoc
nrniv: Couldn't find: sub.hoc
in /cygdrive/C/Users/Ha Ngo/Desktop/newtest/main.hoc near line 2
load_file("sub.hoc")
^
0
back in main
oc>
-
- Site Admin
- Posts: 6300
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Re: Input a vector to neuron
I think that you should move all of your own files out of NEURON's installation tree, and put them in a folder that is in some location outside of the Windows system directories. You might want to put that folder in
C:\Users\Ha Ngo\Desktop
or
C:\Users\Ha Ngo\Documents
Then do a complete uninstall of NEURON (use NEURON's own Uninstall program, which you'll find in the NEURON Program Group). After that is finished, check to make sure that there is no
C:\nrn, C:\nrn72, or C:\nrn73
and if you see one, delete it and all of its subdirectories.
Then get the most recent 32 bit (Cygwin) installer for NEURON from http://www.neuron.yale.edu/neuron/download,
install that on your PC,
and try double clicking on main.hoc
C:\Users\Ha Ngo\Desktop
or
C:\Users\Ha Ngo\Documents
Then do a complete uninstall of NEURON (use NEURON's own Uninstall program, which you'll find in the NEURON Program Group). After that is finished, check to make sure that there is no
C:\nrn, C:\nrn72, or C:\nrn73
and if you see one, delete it and all of its subdirectories.
Then get the most recent 32 bit (Cygwin) installer for NEURON from http://www.neuron.yale.edu/neuron/download,
install that on your PC,
and try double clicking on main.hoc