Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Input variable from workspace within a function
Date: Thu, 20 Sep 2007 19:16:08 +0000 (UTC)
Organization: Atlantic Inertial Systems
Lines: 58
Message-ID: <fcugto$3rf$1@fred.mathworks.com>
References: <fcucjg$k1q$1@fred.mathworks.com> <fcueeb$jnj$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1190315768 3951 172.30.248.35 (20 Sep 2007 19:16:08 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 20 Sep 2007 19:16:08 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1091020
Xref: news.mathworks.com comp.soft-sys.matlab:429485



"David " <dave@bigcompany.com> wrote in message
<fcueeb$jnj$1@fred.mathworks.com>...
> "First Last" <nospam@nospamplease.com> wrote in message 
> <fcucjg$k1q$1@fred.mathworks.com>...
> > I have a variable, var2, in my desktop workspace, which I
> > can manipulate, declare, and save just fine. 
> > 
> > However, I have a function that utilizes the 'input' 
> command
> > that asks, for instance:
> > 
> > function data = myfn
> >      variable1 = input('please input variable1: ');
> >      if isempty(variable1)
> >          do some task here
> >      end
> >      
> >      data = somecalc(variable1)
> > end
> > 
> > However I want to assign 'var2' to 'variable1' within the
> > function call. Without making it an input to the 
> function (I
> > sort of just answered my question), is there a way of
> > addressing the variable workspace outside of the 
> function's
> > workspace? 
> > 
> > Thanks ... 
> 
> your 'desktop workspace' is commonly called the 'base' 
> workspace.  each function (not script) gets its own 
> workspace.  functions can access the base workspace using 
> the evalin and assignin commands, take a look at them in 
> the help for syntax.
> 

^^ shudder

You "could" do it that what, but this is what's known as a
bad programming practice. (not a shot at dave, I just don't
want to encourage bad behavior)

use a script file:
  variable1 = input('please input variable1: ');
  
  workspaceData = myfcn(variable1, var2);

This calls your function file
  function data = myfn(variable1, var2)
      if isempty(variable1)
          do some task here
      end
      
      data = somecalc(variable1)
  end

~Adam