Path: news.mathworks.com!not-for-mail
From: "John D'Errico" <woodchips@rochester.rr.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Using workspace variable in m-file
Date: Sat, 6 Sep 2008 14:42:01 +0000 (UTC)
Organization: John D'Errico (1-3LEW5R)
Lines: 39
Message-ID: <g9u4rp$fb5$1@fred.mathworks.com>
References: <g9t86u$cu5$1@fred.mathworks.com> <33eac32d-6e15-4ff2-895f-f04ec68458d0@d1g2000hsg.googlegroups.com>
Reply-To: "John D'Errico" <woodchips@rochester.rr.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1220712121 15717 172.30.248.37 (6 Sep 2008 14:42:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 6 Sep 2008 14:42:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869215
Xref: news.mathworks.com comp.soft-sys.matlab:488940



Andrew <andrewkgentile@gmail.com> wrote in message <33eac32d-6e15-4ff2-895f-f04ec68458d0@d1g2000hsg.googlegroups.com>...
> On Sep 6, 12:33 am, "jay kumar" <kumar.jay....@gmail.com> wrote:
> > Hi,
> > I want to use workspace variables in my m-file and i want to do some operation on that variables in m-file. but that variables and their values are available in workspace.
> >
> > e.g I want to multiply two transfer functions and obtain bode plot for different values of parameters but that two transfer functions are available in workspace
> >
> > I do not want to write transfer functions again in m-file. Instead of that i want to obtain it from workspace.
> 
> If you define the transfer functions in the workspace (from the
> command page, I assume), then they are already in the workspace.  The
> m-file will already see the variable, unless you begin your m-files as
> I do with clear all; close all commands.  Once the variables are in
> the workspace, the m-file will automatically recognize them.

This is only true if the m-file is a script.

Scripts are generally a poor choice, especially 
if you begin them with clear commands.

Far better is to learn to use and write functions.
Functions have their own workspace, so you
need not worry about polluting the base
workspace with the odd variables created inside
your functions. This is a far cleaner way to
build your tools. Make small functions that do
a single thing. In some languages these are
called idioms. Build up an idiom library of your
own, formed both from the functions you have
written to solve your own specific type of
problems, and from those useful utilities that
you have downloaded from the file exchange.

You will be surprised how fast these functions
accumulate, as well as how useful they will be.
Before long, other people you work with will
find out about your collection of idioms.

John