help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Updating a variable


From: Andy Buckle
Subject: Re: Updating a variable
Date: Wed, 18 Jan 2012 15:18:36 +0000

On 18 January 2012 14:13, Juan Pablo Carbajal <address@hidden> wrote:
> On Wed, Jan 18, 2012 at 6:47 AM, witham <address@hidden> wrote:
>> I believe this will be very simple, but I don't see what to do. I couldn't
>> find anything in Octave FAQs about this. Why isn't A being updated?
>>
>>>> d=1
>> d =  1
>>>> A=d*8
>> A =  8
>>>> d=2
>> d =  2
>>>> A
>> A =  8
>>
>> A stays = to 8, why doesn't it change to 16? How can I get it to change to
>> 16?
>>
>> Thanks.
>>
>> --
>> View this message in context: 
>> http://octave.1599824.n4.nabble.com/Updating-a-variable-tp4305773p4305773.html
>> Sent from the Octave - General mailing list archive at Nabble.com.
>> _______________________________________________
>> Help-octave mailing list
>> address@hidden
>> https://mailman.cae.wisc.edu/listinfo/help-octave
>
> Hi,
> When you do
> A = d*8
> The variable A stores the value of the result. It is not linked to d
> in anyway. To produce such behavior you could define A as a function
> of d, for example
>
>> A =@(x)x*8
>
> Then
>> d = 1;
>>A(d)
> ans = 8
>>A(3)
> ans = 24
>
> etc...

I just wanted to add a bit, so you could read around. In that example
an anonymous function was used

http://www.gnu.org/software/octave/doc/interpreter/Anonymous-Functions.html

More complex functions would be defined in a file.

http://www.gnu.org/software/octave/doc/interpreter/Function-Files.html

(those pages out for the SOPA protest now, you can use google's cached version).

-- 
/* andy buckle */


reply via email to

[Prev in Thread] Current Thread [Next in Thread]