vector save every run()

The basics of how to develop, test, and use models.
Post Reply
okanerkaymaz

vector save every run()

Post by okanerkaymaz »

i want to do save vector's data into .dat file when i press init&run button on GUI "RUN CONTROL" in Neuron
but i can't do it
i write a .hoc file that is folowing

Code: Select all

 
/* ok.hoc file */


proc run(){
objref data,fok
data=new Vector()
data.record(&soma.v(0.5))
fok=new File()
fok.wopen("okan.dat")
data.printf(fok)
fok.close()
print soma.v(0.5)
}   
i called it in mosinit.hoc file with load_file("ok.hoc")

best regard
Raj
Posts: 220
Joined: Thu Jun 09, 2005 1:09 pm
Location: Groningen, The Netherlands
Contact:

Post by Raj »

You have overwritten the standard run command, if you do not include the original commands that are in that function you end running only your self written code.

The original procedure is (nrn 5.8: stdrun.hoc)

Code: Select all

proc run() {
	running_ = 1
	stdinit()
	continuerun(tstop)
}
Including this in your code gives:

Code: Select all

proc run(){

// Prepare data structures
objref data,fok
data=new Vector()


// Start recording
data.record(&soma.v(0.5))

// Start run
running_ = 1
stdinit()
continuerun(tstop)

// Export result to file
fok=new File()
fok.wopen("okan.dat")
data.printf(fok)
fok.close()

// Plot soma membrane potential to command window???
print soma.v(0.5)
}   
But as Ted pointed out:
https://www.neuron.yale.edu/phpBB2/view ... initialize
the record statement should actually be moved out of this code. So if you are calling the code from a loop for setting parameters you might aswell rename your function to myRun and define the variable you will use for recording first by calling prepareMyRun(). Also you don't have to overwrite the standard run system to get this job done, therefore it is better if you don't:

Code: Select all

proc prepareMyRun(){
	// Prepare data structures
	objref data
	data=new Vector()
	// Start recording
	data.record(&soma.v(0.5))
}

Code: Select all

proc myRun(){

objref fok
// Start run
run()

// Export result to file
fok=new File()
fok.wopen("okan.dat")
data.printf(fok)
fok.close()

// Plot soma membrane potential to command window???
print soma.v(0.5)
}   
IF you still want to start these functions from the GUI just add:

Code: Select all

xpanel("myRunController")
xbutton("Prepare my simulation", "prepareMyRun()")
xbutton("Run my simulation", "myRun()")
xpanel()
okanerkaymaz

Post by okanerkaymaz »

firstly i thanks for reply dear Raj
but i can't run
it doesn't run evry press button and also it doesn't overwrite okan.dat file
is there do it different anyway
Raj
Posts: 220
Joined: Thu Jun 09, 2005 1:09 pm
Location: Groningen, The Netherlands
Contact:

Post by Raj »

Did you put objref data,fok outside of the functions aswell? By the way the data might actually get appended to the existing file.
okanerkaymaz

Post by okanerkaymaz »

so thanks Raj
i resoled this problem but
i have new a problem and also i wan to import this data into matlab but
i can't do it

i wan to save data like flowing list


45.36 33.84 39.6............n

50.87 35.98 43.43............n

56.05 38.55 47.3............n

60.49 41.36 50.92............n

67.17 46.92 57.05............n

73.82 52.8 63.31............n

79.72 56.43 68.07............n

80.14 56.79 68.47............n

74.54 51.83 63.18............n
Raj
Posts: 220
Joined: Thu Jun 09, 2005 1:09 pm
Location: Groningen, The Netherlands
Contact:

Post by Raj »

Best option is to save to binary format and pick that up in matlab, see this topic:
https://www.neuron.yale.edu/phpBB2/view ... tin+miller


Alternatively I think a simple load command might suffice in your case:

Code: Select all

load filename
should give you the content of the file filename in variable filename.

Another option is to put explicit matlab code into the output generated by Neuron, but I would strongly advice against that. It is a solution I used for sometime. It is good for quick and dirty work but it is not scaleable as all m-files loaded by matlab stay around in Matlabs memory. There are ways to remedy that but they are mere hacks and performance becomes extremely bad for larger data sets. So try the second option first, you don't have to recode your neuron output, and if it doesn't work try the first. Which is probably the best thing to do for the future anyway.
Post Reply