Illustration of Labels and prompts:
The program below prompts the user for endpoints (x1, y1) and (x2, y2) of a line segment, and computes the midpoint of the line segment, that is the point (xm, ym). The coordinates of the midpoint are found by:
The script midpoint.m calls a function entercoords to individually prompt the user for the x- and y-coordinates of the two endpoints, calls the function findmid which computes individually the x- and y-coordinates of the midpoint, and then prints this midpoint. Whenever the program is executed, the output appears like this:
>> midpoint
Put the x coord of the first endpoint: 2
Set the y coord of the first endpoint: 4
Put the x coord of the second endpoint: 3
Set the y coord of the second endpoint: 8
The midpoint is (2.5, 6.0)
In this illustration, the word 'first' or 'second' is passed to the entercoords function so that it can use wherever the word is passed in prompt. The sprintf function creates this customized prompt.