get NEURON data from MATLAB
Moderator: wwlytton
get NEURON data from MATLAB
Dear Admin
I want to simulate a 3D neural network by NEURON & MATLAB that the user enter 2 matrixes in MATLAB (which are the matrix of positions of any neurons and the matrix of weights between neurons), then in NEURON software the network build upon the data which the user has entered in MATLAB and then the voltage of every neurons come back to MATLAB and shown by a graph.so,i don't know how can i transfer matrixes data as input for the p3dadd() function in NEURON and then get back the voltages in MATLAB on a graph.
I want to simulate a 3D neural network by NEURON & MATLAB that the user enter 2 matrixes in MATLAB (which are the matrix of positions of any neurons and the matrix of weights between neurons), then in NEURON software the network build upon the data which the user has entered in MATLAB and then the voltage of every neurons come back to MATLAB and shown by a graph.so,i don't know how can i transfer matrixes data as input for the p3dadd() function in NEURON and then get back the voltages in MATLAB on a graph.
Re: get NEURON data from MATLAB
Hi,
Take a look at: https://www.neuron.yale.edu/phpBB2/viewtopic.php?t=996
The solution I took for sending data to NEURON was not a good solution, but it worked for me, for a specific case that I wanted it for: "update several parameters in neuron, do the simulation, back to matlab, do the computations, optimize parameters, then go back to neuron again." this process continues until desired results are achieved.
The solution I took, was to write parameters in a simple .dat file. This file looked like this:
Then I call Neuron using system(hoc_path) command in matlab. hoc_path is the path for my .hoc file to start simulation. in Neuron I use codes below to update parameter values:
started simulation by "run()", saved them to a file, and quit() Neuron.
I hope this could be a little help.
Take a look at: https://www.neuron.yale.edu/phpBB2/viewtopic.php?t=996
The solution I took for sending data to NEURON was not a good solution, but it worked for me, for a specific case that I wanted it for: "update several parameters in neuron, do the simulation, back to matlab, do the computations, optimize parameters, then go back to neuron again." this process continues until desired results are achieved.
The solution I took, was to write parameters in a simple .dat file. This file looked like this:
Code: Select all
para1 = value1
para2 = value2
para3 = value3
Code: Select all
objref para_file
para_file = new File()
xopen("para.dat")
para_file.close()
I hope this could be a little help.
Re: get NEURON data from MATLAB
Thanks for reply,but I have a problem yet.
I save the data in a ".mat" MATLAB file,so i don't know how to read this file by neuron or convert this file as a data file,".dat" file, in order to become readable by NEURON.
if u know please help me..
I save the data in a ".mat" MATLAB file,so i don't know how to read this file by neuron or convert this file as a data file,".dat" file, in order to become readable by NEURON.
if u know please help me..

 Site Admin
 Posts: 5625
 Joined: Wed May 18, 2005 4:50 pm
 Location: Yale University School of Medicine
 Contact:
Re: get NEURON data from MATLAB
NEURON can read and write plain text (plain ASCII). See the Programmer's Reference documentation of the File class and its methods
http://www.neuron.yale.edu/neuron/stati ... /file.html
http://www.neuron.yale.edu/neuron/stati ... /file.html
Re: get NEURON data from MATLAB
thanks for ur answer it was solved a part of my problem,I have also the other one:
I use this code to connect MATLAB to Neuron :
but the result is like this:
I use this code to connect MATLAB to Neuron :
Code: Select all
[status,result]=system('C:\nrn62\bin\nrniv.exe nobanner MainFun.hoc c quit()')
May you tell me what can I do to correct this?.....
status =
0
result =
/cygdrive/c/nrn62/bin/nrniv: can't open MainFun.hoc

 Site Admin
 Posts: 5625
 Joined: Wed May 18, 2005 4:50 pm
 Location: Yale University School of Medicine
 Contact:
Re: get NEURON data from MATLAB
Make sure that your working directory contains MainFun.hoc
You might also try
[status,result]=system('C:\nrn62\bin\nrniv.exe nobanner c "print getcwd()" c "quit()"')
You might also try
[status,result]=system('C:\nrn62\bin\nrniv.exe nobanner c "print getcwd()" c "quit()"')
Re: get NEURON data from MATLAB
working directory is the directory which I save the matlab file?!
Re: get NEURON data from MATLAB
The same directory that you saved your .hoc file in it.nasrin.sh wrote:working directory is the directory which I save the matlab file?!

 Site Admin
 Posts: 5625
 Joined: Wed May 18, 2005 4:50 pm
 Location: Yale University School of Medicine
 Contact:
Re: get NEURON data from MATLAB
The working directory is the default location for NEURON's file reading and writing operations. Usually it's where you started NEURON, so if you start NEURON by double clicking on a hoc file, it's the directory that contains that hoc file; if you're running Linux or UNIX or OS X and start NEURON by typing
nrngui somefilename.hoc
it's the directory that contains somefilename.hoc
hoc allows you to change the working directory with chdir() (see the Programmer's Reference); you can also change the working directory with
NEURON Main Menu / File / working dir
or
NEURON Main Menu / File / recent dir
nrngui somefilename.hoc
it's the directory that contains somefilename.hoc
hoc allows you to change the working directory with chdir() (see the Programmer's Reference); you can also change the working directory with
NEURON Main Menu / File / working dir
or
NEURON Main Menu / File / recent dir
Re: get NEURON data from MATLAB
I place My hoc file in that working directory,this code doesn't cause any errors,but when I run the MATLAB file,my .hoc file doesn't execute!how can this be done?
Re: get NEURON data from MATLAB
To help diagnose the problem we would need to know two things.
1) what is the full path to MainFun.hoc
2) what is the path you find youself in when you execute the
[status, result]=system(...) command. This ought to be able to be determined with
The trick is to get those to match. Perhapy by moving MainFun.hoc to the place indicated by 2).
If the folders already match, I'd try changing the name "MainFun.hoc" to mainfun.hoc and use only
lower case. Perhaps matlab does something with the case.
1) what is the full path to MainFun.hoc
2) what is the path you find youself in when you execute the
[status, result]=system(...) command. This ought to be able to be determined with
Code: Select all
[status,result]=system('C:\nrn62\bin\nrniv.exe nobanner c "print getcwd()" c "quit()"')
If the folders already match, I'd try changing the name "MainFun.hoc" to mainfun.hoc and use only
lower case. Perhaps matlab does something with the case.
Re: get NEURON data from MATLAB
thanks for reply.I did whatever you said.but nothing is changed.shouldn't I mention the name of .hoc file in Matlab program.?I mean in the following code:
this is the Matlab code I use,If it has a problem, please tell me...
Code: Select all
clear
clc
w=input('Enter the matrix of Weight(n*n):');
[n1 m1]=size(w);
while(n1~=m1)
w=input('Enter the matrix of Weight again:');
[n1 m1]=size(w);
end
p=input('Enter the matrix of Position(n*3):');
[n m]=size(p);
while(m~=3n~=n1)
p=input('Enter the matrix of Position again:');
[n m]=size(p);
end
save MyDataP.dat p ascii
save MyDataW.dat w ascii
save MyDataN.dat n ascii
fid = fopen('MyDataP.dat','r+');
fid1 = fopen('MyDataW.dat','r+');
fid2 = fopen('MyDataN.dat','r+');
fclose('all')
[status,result]=system('C:\nrn70\bin\nrniv.exe nobanner c "print getcwd()" c "quit()"')
...
Last edited by nasrin.sh on Wed Sep 29, 2010 2:33 am, edited 1 time in total.
Re: get NEURON data from MATLAB
please someone help me,I really need an urgent answer..

 Site Admin
 Posts: 5625
 Joined: Wed May 18, 2005 4:50 pm
 Location: Yale University School of Medicine
 Contact:
Re: get NEURON data from MATLAB
To help us help you, please do the following things:
1. Tell us what is the full path to MainFun.hoc
2. Start your MatLab program, then execute the followig MatLab commandand tell us what MatLab prints in response to this command.
1. Tell us what is the full path to MainFun.hoc
2. Start your MatLab program, then execute the followig MatLab command
Code: Select all
[status,result]=system('C:\nrn62\bin\nrniv.exe nobanner c "print getcwd()" c "quit()"')
Re: get NEURON data from MATLAB
I put my .hoc file in this path:
run the neuron and my .hoc file,
and the response is this:C:\nrn70\bin
and my Matlab file is here:ans =
0
status =
0
result =
/cygdrive/c/Users/Nasrin/Documents/MATLAB/
you know,I want when I execute the Matlab file and the compiler see this codec/Users/Nasrin/Documents/MATLAB/
Code: Select all
[status,result]=system('C:\nrn70\bin\nrniv.exe nobanner c "print getcwd()" c "quit()"')