Update an array

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Update an array

afullo
Is there a way to update an array depending on some variables, when these variables are changed?

For example, I was thinking whether is possible to obtain something like that:

a = 1;
A = [1 a a^2];
A
A =

   1   1   1

a = 2;
update A;
A
A =

   1   2   4

In this case it could seem not of much interest (why to use a new command, while it is sufficient to repeat A = [1 a a^2] ?), but in fact it could be useful when the definition of A is more complicated (for example, it could involve more than one variabile, or it could be piecewise).

Thanks in advance.
Reply | Threaded
Open this post in threaded view
|

Re: Update an array

Markus Bergholz



On Fri, Aug 29, 2014 at 10:11 PM, afullo <[hidden email]> wrote:
Is there a way to update an array depending on some variables, when these
variables are changed?

For example, I was thinking whether is possible to obtain something like
that:

a = 1;
A = [1 a a^2];
A
A =

   1   1   1

a = 2;
*update* A;
A
A =

   1   2   4


afaik, there is no "auto-update".
 
In this case it could seem not of much interest (why to use a new command,
while it is sufficient to repeat A = [1 a a^2] ?), but in fact it could be
useful when the definition of A is more complicated (for example, it could
involve more than one variabile, or it could be piecewise).

then simply put all your complicated code to calculate A into a function ;)

 

Thanks in advance.



--
View this message in context: http://octave.1599824.n4.nabble.com/Update-an-array-tp4666280.html
Sent from the Octave - General mailing list archive at Nabble.com.

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave



--
icq: 167498924
XMPP|Jabber: [hidden email]

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave