The function will work in two modes. 1) Interactive mode where the user will be able to click on the plot one or more times to choose where the text is to be placed.

engineering

Description

Modes of Operation 

The function will work in two modes. 1) Interactive mode where the user will be able to click on the plot one or more times to choose where the text is to be placed. Each left-click will place the text at that location and will erase any previous placements of the text by this function call. A right click indicates that the user is satisfied with the text placement and is done choosing. 2) By giving a location for the text, as the second argument, the caller indicates that the text will be placed at that location without user interaction.


Variable Number and Types of Arguments and Return Value The function will take a variable number of arguments. 


 The first argument will be the string to be placed on the plot. This is the only mandatory argument. If it is all that is given, the function will run in interactive mode. 


 If there is a second argument and it is a vector array of 2 numbers, then it is the position to place the text. The means the function is to work non-interactively and place the text without requiring that the user choose a location. There are several ways to do this. But, learning about the Matlab function isnumeric may be useful here. 


 If there is a second argument and the second argument is a string with the value 'Prompt' then the third argument must also be a string and this prompt string that will be printed to the console to alert the user that some text is to be placed. This is only for interactive mode. The Matlab function isequal is useful for determining whether two strings are equal. 


 Any other arguments passed to MyPutText are assumed to be key-value pairs that MyPutText will pass straight on to Matlab's text function. MyPutText should not check what they are, just assume they are for text and pass them along. Note that common key-value pairs for text include the text color, font style, etc. 


 Handling the variable length argument lists will require a little thought. What we did in HW09 will be useful and review of the Matlab reference page on varargin will be needed to see how to pass on all or part of an argument list to another function. There is more than one way to do this. Figuring out how to get a slice of a cell array will be useful. 


 When the text is placed interactively, the function will print to the console the final location [x, y] where the text was finally placed. That may be used in future (non-interactive) calls to this function. 


 When it is done, if the call to MyPutText is assigned to a variable (check Matlab's nargout to see), MyPutText will return the text object that is returned by its last call to Matlab's text, which creates the text on the plot.


Related Questions in engineering category