|
"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
|