COMPLETE QUESTION:
Write a function nexthour that receives one integer argument, which is an hour of the day, and returns the next hour. This assumes a 12-hour clock; so, for example, the next hour after 12 would be 1. Here are two examples of calling this function.
>> fprintf('The next hour will be %d.\n', nexthour(3))
the next hour will be 4
>> fprintf('The next hour will be %d.\n', nexthour(12))
the next hour will be 1
Answer:
The following CODE in MATLAB will accomplish this
>> nexthour = input('Please enter a time here: ');
if (nexthour >= 1) && (nexthour< 12)
nexthour = nexthour+ 1
elseif (nexthour == 12)
nexthour = 1
else
disp('You entered an invalid time')
end
Explanation:
In the Matlab code above, the input function is used to receive a value for time in hours (1-12) next we use the if statement to check that the time entered is between 1 and 11 and add 1 as the next hour, else if the value entered is 12, we assign 1 as the next hour. For every other inputs an error message is displayed.