Page 1 of 2
get NEURON data from MATLAB
Posted: Mon Sep 20, 2010 11:08 pm
by nasrin.sh
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.
Re: get NEURON data from MATLAB
Posted: Tue Sep 21, 2010 4:59 am
by hassanf
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:
Code: Select all
para1 = value1
para2 = value2
para3 = value3
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:
Code: Select all
objref para_file
para_file = new File()
xopen("para.dat")
para_file.close()
started simulation by "run()", saved them to a file, and quit() Neuron.
I hope this could be a little help.
Re: get NEURON data from MATLAB
Posted: Tue Sep 21, 2010 8:28 am
by nasrin.sh
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..
Re: get NEURON data from MATLAB
Posted: Tue Sep 21, 2010 4:03 pm
by ted
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
Re: get NEURON data from MATLAB
Posted: Wed Sep 22, 2010 1:22 am
by nasrin.sh
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 :
Code: Select all
[status,result]=system('C:\nrn62\bin\nrniv.exe -nobanner MainFun.hoc -c quit()')
but the result is like this:
...
status =
0
result =
/cygdrive/c/nrn62/bin/nrniv: can't open MainFun.hoc
May you tell me what can I do to correct this?..
Re: get NEURON data from MATLAB
Posted: Wed Sep 22, 2010 3:19 pm
by ted
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()"')
Re: get NEURON data from MATLAB
Posted: Wed Sep 22, 2010 3:50 pm
by nasrin.sh
working directory is the directory which I save the matlab file?!
Re: get NEURON data from MATLAB
Posted: Wed Sep 22, 2010 5:05 pm
by hassanf
nasrin.sh wrote:working directory is the directory which I save the matlab file?!
The same directory that you saved your .hoc file in it.
Re: get NEURON data from MATLAB
Posted: Wed Sep 22, 2010 6:56 pm
by ted
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
Re: get NEURON data from MATLAB
Posted: Thu Sep 23, 2010 4:12 pm
by nasrin.sh
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
Posted: Thu Sep 23, 2010 6:49 pm
by hines
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
Code: Select all
[status,result]=system('C:\nrn62\bin\nrniv.exe -nobanner -c "print getcwd()" -c "quit()"')
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.
Re: get NEURON data from MATLAB
Posted: Fri Sep 24, 2010 10:28 am
by nasrin.sh
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:
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~=3||n~=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()"')
...
this is the Matlab code I use,If it has a problem, please tell me...
Re: get NEURON data from MATLAB
Posted: Mon Sep 27, 2010 11:51 pm
by nasrin.sh
please someone help me,I really need an urgent answer..
Re: get NEURON data from MATLAB
Posted: Tue Sep 28, 2010 5:35 pm
by ted
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 command
Code: Select all
[status,result]=system('C:\nrn62\bin\nrniv.exe -nobanner -c "print getcwd()" -c "quit()"')
and tell us what MatLab prints in response to this command.
Re: get NEURON data from MATLAB
Posted: Wed Sep 29, 2010 4:08 am
by nasrin.sh
I put my .hoc file in this path:
C:\nrn70\bin
and the response is this:
ans =
0
status =
0
result =
/cygdrive/c/Users/Nasrin/Documents/MATLAB/
and my Matlab file is here:
c/Users/Nasrin/Documents/MATLAB/
you know,I want when I execute the Matlab file and the compiler see this code
Code: Select all
[status,result]=system('C:\nrn70\bin\nrniv.exe -nobanner -c "print getcwd()" -c "quit()"')
run the neuron and my .hoc file,