How to write a function with 3 inputs and a calculated if statement?

I am currently stuck on this question and would greatly appreciate the help of how or where I should start.
Create a function that evaluates whether or not the height of a machined part is within the manufacturer's tolerance (i.e. the acceptable manufacturing limits). The function will take three input arguments--the specified value for the height, the actual value of the height, and the tolerance (how much the actual value can be over or under the specified value for the height). If your object is within the tolerance, you should display, "Within tolerance!", and if it is not, you should display, "Not within specified tolerance. Create a new part." Test your function for a specified height of 2 meters, an actual value of 1.995 meters, and a tolerance of 0.002 meters.

Antworten (1)

KSSV
KSSV am 1 Feb. 2021
If a, b is your original and approximate values, tol is tolerance. You have to use:
if abs(a-b)<=tol
Next, read about how to create a funcition, if, fprintf.

Gefragt:

am 1 Feb. 2021

Beantwortet:

am 1 Feb. 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by