|
|
function s=subvar(s0,v0,v1)
$Id: subvar.m,v 1.4 2003-01-08 03:46:16-06 brinkman Exp $
(c) 2001, Peter Brinkmann (brinkman@math.uiuc.edu)
subvar: substitutes a variable for another in an expression
Usage example: subvar('sin(i)','i','x') yields 'sin(x)'
Parameters:
s0: expression
v0: old variable
v1: new variable
Returns:
s: s0 with all occurrences of v0 replaced by v1
v0 must be a variable name. v1 can be almost anything, but the user is
responsible for proper use of parentheses. For instance, if v1 is a
sum, then it is wise to enclose it in parentheses. subvar will _not_ do
this automatically.
Note that subvar parses the expression s0 and only replaces occurrences
of the _variable_ v0 by v1. In particular, it doesn't blindly substitute
the string v1 for any substring v0.
Although this function behaves much like Matlab's subs function, I had
to reimplement this because (a) Octave has no such substitute function,
and (b) the subs function automatically encloses v1 in parentheses,
which is undesirable for the purposes of Iode.
|