MATLAB: Create a matrix “z” which has the same elements as “x”. If any entry in “z” % is even, increase that entry by one.

if statementloop

Hello,
Can anyone helo me with this one?
Create a matrix "z" which has the same elements as "x". If any entry in "z" is even, increase that entry by one.

Best Answer

What is the part that you're stuck on?
you need to use a for loop and an if else like this:
.... % defining your variables and all that
for i=1:numel(z)
if mod(z(i),2) == 0 % thats how to see if it's even or not
z(i) = z(i)+1; % something like this
end
end
Related Question