replace
Syntax
replace(X, oldValue, newValue)
Arguments
X is a vector/matrix.
oldValue is the value to be replaced.
noewValue is the new value.
Details
Replace oldValue with newValue in X. replace!
is the in-place change version of replace
.
Examples
$ x=1 1 3;
$ x=x.replace(1,2);
$ x
[2,2,3];
$ m=1..4$2:2;
$ m
#0 |
#1 |
---|---|
1 |
3 |
2 |
4 |
$ m=m.replace(2,1);
$ m
#0 |
#1 |
---|---|
1 |
3 |
1 |
4 |
$ m.replace!(1,6);
#0 |
#1 |
---|---|
6 |
3 |
6 |
4 |