get NEURON data from MATLAB

Moderator: wwlytton

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

get NEURON data from MATLAB

Post by nasrin.sh » Mon Sep 20, 2010 11:08 pm

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.

hassanf
Posts: 5
Joined: Mon Jun 14, 2010 1:52 pm

Re: get NEURON data from MATLAB

Post by hassanf » Tue Sep 21, 2010 4:59 am

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.

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

Re: get NEURON data from MATLAB

Post by nasrin.sh » Tue Sep 21, 2010 8:28 am

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..

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

Re: get NEURON data from MATLAB

Post by ted » Tue Sep 21, 2010 4:03 pm

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

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

Re: get NEURON data from MATLAB

Post by nasrin.sh » Wed Sep 22, 2010 1:22 am

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?..

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

Re: get NEURON data from MATLAB

Post by ted » Wed Sep 22, 2010 3:19 pm

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()"')

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

Re: get NEURON data from MATLAB

Post by nasrin.sh » Wed Sep 22, 2010 3:50 pm

working directory is the directory which I save the matlab file?!

hassanf
Posts: 5
Joined: Mon Jun 14, 2010 1:52 pm

Re: get NEURON data from MATLAB

Post by hassanf » Wed Sep 22, 2010 5:05 pm

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.

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

Re: get NEURON data from MATLAB

Post by ted » Wed Sep 22, 2010 6:56 pm

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

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

Re: get NEURON data from MATLAB

Post by nasrin.sh » Thu Sep 23, 2010 4:12 pm

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?

hines
Site Admin
Posts: 1575
Joined: Wed May 18, 2005 3:32 pm

Re: get NEURON data from MATLAB

Post by hines » Thu Sep 23, 2010 6:49 pm

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.

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

Re: get NEURON data from MATLAB

Post by nasrin.sh » Fri Sep 24, 2010 10:28 am

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...
Last edited by nasrin.sh on Wed Sep 29, 2010 2:33 am, edited 1 time in total.

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

Re: get NEURON data from MATLAB

Post by nasrin.sh » Mon Sep 27, 2010 11:51 pm

please someone help me,I really need an urgent answer..

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

Re: get NEURON data from MATLAB

Post by ted » Tue Sep 28, 2010 5:35 pm

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.

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

Re: get NEURON data from MATLAB

Post by nasrin.sh » Wed Sep 29, 2010 4:08 am

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,

Post Reply