Write a function called loopCompare that takes in two arrays

Write a function called loopCompare that takes in two arrays. XValues and YValues. It should return an output array, ZValues. This function should use a loop with a conditional statement inside of it to implement the following: When XValues(i) > YValues(i), ZValues(i) - XValues(i) When XValues(i) -

Solution

function ZValues = loopCompare(XValues, YValues)
   n = length(XValues);
   ZValues = zeros(1, n);
   for i = 1:n
       if(XValues(i) > YValues(i))
           ZValues(i) = XValues(i);
       else
           ZValues(i) = YValues(i);
       end
   end
end

 Write a function called loopCompare that takes in two arrays. XValues and YValues. It should return an output array, ZValues. This function should use a loop w

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site