Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: Passing Matlab Variable to UNIX

Subject: Passing Matlab Variable to UNIX

From: Nitin Chhabra

Date: 16 May, 2008 05:33:02

Message: 1 of 3

Hi,

I am trying to pass the Matlab variables to unix function.
One crude way is to write the variables into temporary
file and read this file via unix script.

Is there any better way to do the same.
Passing the argument directly from matlab to unix script
without writing a temporary file

Subject: Passing Matlab Variable to UNIX

From: David Chorlian

Date: 16 May, 2008 17:20:03

Message: 2 of 3

"Nitin Chhabra" <nitin.chhabra@st.com> wrote in message
<g0j6ad$ll5$1@fred.mathworks.com>...
> Hi,
>
> I am trying to pass the Matlab variables to unix function.
> One crude way is to write the variables into temporary
> file and read this file via unix script.
>
> Is there any better way to do the same.
> Passing the argument directly from matlab to unix script
> without writing a temporary file

If you're working from within the Matlab command window:
command = sprintf('%s %d', unix_script_name, matlab_var);
unix(command)

If you're using a Unix script to execute a Matlab function
or script, you could use fprintf(1, ...) inside your Matlab
script to print to stdout.

That is, inside your Unix script
var=`matlab -nodisplay -nojvm $matlab_file`

Of course, this only interesting if the value of matlab_file
can be set by passing arguments to the Unix script.


Subject: Passing Matlab Variable to UNIX

From: Nitin Chhabra

Date: 19 May, 2008 03:44:01

Message: 3 of 3

"David Chorlian" <davidc@panix.remove.this.com> wrote in
message <g0kfo3$rf2$1@fred.mathworks.com>...
> "Nitin Chhabra" <nitin.chhabra@st.com> wrote in message
> <g0j6ad$ll5$1@fred.mathworks.com>...
> > Hi,
> >
> > I am trying to pass the Matlab variables to unix
function.
> > One crude way is to write the variables into temporary
> > file and read this file via unix script.
> >
> > Is there any better way to do the same.
> > Passing the argument directly from matlab to unix
script
> > without writing a temporary file
>
> If you're working from within the Matlab command window:
> command = sprintf('%s %d', unix_script_name, matlab_var);
> unix(command)
>
> If you're using a Unix script to execute a Matlab
function
> or script, you could use fprintf(1, ...) inside your
Matlab
> script to print to stdout.
>
> That is, inside your Unix script
> var=`matlab -nodisplay -nojvm $matlab_file`
>
> Of course, this only interesting if the value of
matlab_file
> can be set by passing arguments to the Unix script.
>
>

Thanks David !

I tried the first method and it really solved my problem.

with reagrds,
Nitin

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
matlab Nitin Chhabra 16 May, 2008 01:35:03
variable Nitin Chhabra 16 May, 2008 01:35:03
passing Nitin Chhabra 16 May, 2008 01:35:03
unix Nitin Chhabra 16 May, 2008 01:35:03
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics