MATLAB: How to create an output of a vector by operating on individual elements for different conditions

array operationslogical?MATLAB

Hi,
I have a vector X = 1:2:21, How do I get an output by checking th conditioin of each element and carrying a culculation if it meets the condition otherwise the output is a set value. eg for the vector
X = 1 3 5 7 9 11 13 15 17 19 21;
check if elements are greater than 13, X(X>13) then for these elements calculate X(X>13)*2 otherwise the element is 5. The output should give a new matrix Y such that:
Y = 5 5 5 5 5 5 26 30 34 38 42;
Thanks in Advance!

Best Answer

Any illustration with your vectors would amount to doing this for you, and since this seems to be a homework problem, we only give hints.
So I refer you to the documentation section on Indexing with Logical Values (link).