Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using bash shell inside Matlab

Tags:

bash

matlab

I'm trying to put a large set of bash commands into a matlab script and manage my variables (like file paths, parameters etc) from there. It is also needed because this workflow requires manual intervention at certain steps and I would like to use the step debugger for this.

The problem is, I don't understand how matlab interfaces with bash shell. I can't do system('source .bash_profile') to define my bash variables. Similarly I can't define them by hand and read them either, e.g. system('export var=somepath') and then system('echo $var') returns nothing.

What is the correct way of defining variables in bash inside matlab's command window? How can I construct a workflow of commands which will use the variables I defined as well as those in my .bash_profile?

like image 273
ali Avatar asked Jul 23 '10 21:07

ali


People also ask

Does MATLAB support Linux?

MATLAB must be launched from the command line on Linux.

How do I run a command in MATLAB?

Go to the Editor tab and click Run . MATLAB® displays the list of commands available for running the function. Click the last item in the list and replace the text type code to run with a call to the function including the required input arguments.

Why do we add #!/ Bin bash?

The shebang, #!/bin/bash when used in scripts is used to instruct the operating system to use bash as a command interpreter. Each of the systems has its own shells which the system will use to execute its own system scripts.


1 Answers

If all you need to do is set environment variables, do this in MATLAB:

>> setenv('var','somepath')
>> system('echo $var')
like image 113
Gilead Avatar answered Sep 23 '22 11:09

Gilead