MATLAB: Replacing elements in an array

arrayMATLABreplacereplacing

Didn't find a relevant answer.
Suppose we have an array
R=[1 2 1 2 2 2]';
How to replace "2" with "4" ?
Thank you.

Best Answer

R=[1 2 1 2 2 2]';
R(R==2) = 4;