call Matlab script in BV 4.0.2

Questions about BrainVisa usage and installation

Moderators: denghien, riviere

Post Reply
as_dub
Posts: 59
Joined: Fri Aug 19, 2005 4:09 pm
Location: Cleveland, Ohio

call Matlab script in BV 4.0.2

Post by as_dub »

Hello!!

Back in BV forum!!! It been a long time... I just downloaded BV 4.0.2 and start to get familiar with it (very nice by the way !!! :D ).
I have a question regarding Matlab:

I couldn't figure out how to call a Matlab script with the latest version of BV. Is that still possible?
Sorry if this question has already been answered in the forum, but when I type 'matlab' in the search field of the forum,I get this answer :
"The following words in your search query were ignored because they are too common words: import matlab"
:roll:

Thanks!!

Anne-Sophie
User avatar
riviere
Site Admin
Posts: 1361
Joined: Tue Jan 06, 2004 12:21 pm
Location: CEA NeuroSpin, Saint Aubin, France
Contact:

Re: call Matlab script in BV 4.0.2

Post by riviere »

Hi Anne-Sophie,

Well, the matlab module has not been maintained any longer because it caused too many compatibility problems: it relied heavily on things we cannot control, like versions of low-level system libraries, and version of Matlab.
So when we need to run matlab now, we do it the cheap way:

Code: Select all

context.system( 'cat matlab_script.m | matlab -nodesktop' )
It's not as powerful since you have to write the script files before calling matlab, you cannot get the results in python, and matlab is restarted and closed each time you need it, but at least it works in every case. That's the way it is used in the fMRI toolbox when using SPM preprocessings.

Denis
as_dub
Posts: 59
Joined: Fri Aug 19, 2005 4:09 pm
Location: Cleveland, Ohio

Re: call Matlab script in BV 4.0.2

Post by as_dub »

Thank you Denis! I will try that.

AnneSo
as_dub
Posts: 59
Joined: Fri Aug 19, 2005 4:09 pm
Location: Cleveland, Ohio

Re: call Matlab script in BV 4.0.2

Post by as_dub »

"you cannot get the results in python" : How saaaaaaad.... :cry:

I installed the "very" old version 3.0.2 on my Fedora 14 64bit... It is possible! (just in case anybody needs help on this)

I will probably also install the latest version of Brainvisa, but with no possibility of loading Matlab results... it limits the use I can have with it. Do you plan to put that feature back sometime?

Thanks!

AnneSo
User avatar
riviere
Site Admin
Posts: 1361
Joined: Tue Jan 06, 2004 12:21 pm
Location: CEA NeuroSpin, Saint Aubin, France
Contact:

Re: call Matlab script in BV 4.0.2

Post by riviere »

Hi,

Well, we could not make pymat work reliably on a range of Matlab versions, of host systems, and of python versions, so we had to drop it. It actually did work for some of them, but we could not provide a solution that would not always work.
Now when I say "you cannot get the results in python", I mean not directly, as matrices. But you can still make a matlab script write a file, and re-read that file from python. The scipy module offers functions to read .mat files as numpy arrays (scipy.io.loadmat()), so apart from the file writing and re-reading, it is still quite efficient, and definitely easier to maintain. There are ways to make it portable also (but not in the simple way I suggested previously with a pipe in the command).
A better solution would be using a socket connection between python and matlab. A work had been started on that idea by Denis Schwartz a few years ago, but not finished and a little bit forgotten.

Denis
as_dub
Posts: 59
Joined: Fri Aug 19, 2005 4:09 pm
Location: Cleveland, Ohio

Re: call Matlab script in BV 4.0.2

Post by as_dub »

Thank you Denis for your answer. I understand your concern about Matlab. It is challenging to follow the versions.. I will explore the tricks that you give me to achieve what I want. Thanks!
AnneSo
Post Reply