From: Fernando Yuji Ono on
Consider this simple function:

function [x] = rand(y)
x = 2*y;

I noticed that I can't use x directly outside the function, like this:

output = x;

So how do I do that?


Message was edited by: Fernando Yuji Ono

From: Walter Roberson on
Fernando Yuji Ono wrote:
> Consider this simple function:
>
> function [x] = rand(y)
> x = 2*y;
>
> I noticed that I can't use x directly outside the function, like this:
>
> output = x;
>
> So how do I do that?

That isn't possible in Matlab for function variables that are declared
as input or output parameters.
From: TideMan on
On Jul 12, 5:23 pm, Fernando Yuji Ono <fernando90...(a)gmail.com> wrote:
> Consider this simple function:
>
> function [x] = rand(y)
>     x = 2*y;
>
> I noticed that I can't use x directly outside the function, like this:
>
> output = x;
>
> So how do I do that?
>
> Message was edited by: Fernando Yuji Ono

What you're doing is silly.
rand is an in-built function.
You should use a different name.

function x=twice(y)
x=2*y;

y=2;
output=twice(y)
From: Fernando Yuji Ono on
Thanks for your answers.
It worked.