Matlab based Please Write a function that validates whether its inputs meet the
ID: 3808188 • Letter: M
Question
Matlab based PleaseWrite a function that validates whether its inputs meet the following criteria: a. It must take exactly three parameters as input. b. The first parameter must be a string that starts with a capital letter. c. The second parameter must be a structure, and the structure must contain a field named mileage. d. The third parameter must be a non-empty array where all numbers in the array must alternate even then odd and each value must be larger than the previous value. Eg: [2 9 1423 66 101 102]
Explanation / Answer
function isValid = validate_input(par1, par2, par3)
if (upper(par1(1)) == par1(1)) & (isstruct(par2)) & (isfiled(par2, 'milage'))
firsttwo = 1
end
condition3 = 1 - isempty(par3)
isValid = firsttwo & condition3
prev = 0
current = 0
for idx = numel(par3)
current = par3(idx)
if (idx % 2) == 0
if current % 2 == 0
isValid = isValid & 1
else
isValid = isValid & 0
end
else
if current % 2 != 0
isValid = isValid & 1
else
isValid = isValid & 0
end
end
isValid = isValid & (current > prev)
end
end