Info

This question is closed. Reopen it to edit or answer.

Replacing an element in a matrix, then storing it as a different variable name

1 view (last 30 days)
Hello!
I am having a hard time replacing an element in a matrix and then being able to rename the new matrix with the replaced values.
For example:
I use
x=[1 2 1; 3 4 3; 5 6 5]
I want to replace all the '3' with '4' AND be able to call the solution x2
I know that I can replace elements with the equation
x(x==3) = 4
but that changes the values in x
I want to create a new matrix with the replaced values as 'x2'
I keep running into the problem of not being able to use "=" more than once in a line of code.
Help is much appreciated!!

Answers (1)

madhan ravi
madhan ravi on 7 Jul 2019
x2 = x;
x2(x2==3) = 4

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!