I would like to write my variables as operations between other variables.
For instance if I put a = c + b
then value that a keeps inside is the numeric result of the operation of a sum between c and b.
If c = 4 and b = 2 then, the value that a keeps is 6.
But I would like that a keeps the symbolic expression instead of the numeric value. and every time I write a in the command windows, matlab cacht the numeric value of c and the numeric value of b of the worspace variable and a sum them.
Normally if you write a, matlab displays the numeric value that is in this variable. Does anyone know how to do this?
You can do this using the symbolic toolbox. Here's an example:
So the definition of
a
is stillb + c
(you can check this by typinga
at the command window) and when you evaluate it usingeval
, it uses the current value ofb
andc
to calculatea
. Note thatb
andc
are no longer symbolic variables and are converted to doubles. Howevera
still is, and the definition holds because by default, the expressions in symbolic variables are held unevaluated.