Opt disp

Jump to: navigation, search
Display a message to the user (sometimes)

Other toolboxes required none
Function category Helper functions
This is a helper function that only exists to aid other functions in QETLAB. If you are an end-user of QETLAB, you likely will never have a reason to use this function.

opt_disp is a function that displays a given message to the user if and only if a specific flag is specified. The only purpose of this function is to reduce the number of if statements within the code of other functions, thus making them a bit more readable.


  • opt_disp(X,VERBOSE)

Argument descriptions

  • X: A string to be displayed to the user.
  • VERBOSE: A flag (either 1 or 0) indicating whether or not X will be displayed.


Display and don't display a message to the user:

>> opt_disp('Hello\n',1)
>> opt_disp('Hello\n',0)


This function is only meant to simplify code within other functions. If you always want to display the message, just use MATLAB's built-in disp or fprintf function. Note that opt_disp uses fprintf, so you may need to end your string with a newline character \n (as in the example) for it to function how you expect.

Source code

Click on "expand" to the right to view the MATLAB source code for this function.

  1. %%  OPT_DISP  Display a message to the user (sometimes)
  2. %   This function has two required arguments:
  3. %     X: the object or message to be displayed
  4. %     VERBOSE: a flag (1 or 0)
  5. %
  6. %   opt_disp(X,VERBOSE) calls fprintf(X) if VERBOSE = 1. If VERBOSE = 0
  7. %   then this function does nothing.
  8. %
  9. %   Only use this function within other functions to easily display (or not
  10. %   display) a message, if there is a "verbose" flag within that function.
  11. %   If you always want to display a message, just use MATLAB's fprintf
  12. %   function directly. The only purpose of this function is to improve
  13. %   readability and reduce if statements in other code.
  14. %
  15. %   URL: http://www.qetlab.com/opt_disp
  17. %   requires: nothing
  18. %   author: Nathaniel Johnston (nathaniel@njohnston.ca)
  19. %   package: QETLAB
  20. %   last updated: December 3, 2012
  22. function opt_disp(X,verbose)
  24. if(verbose)
  25.     fprintf(X);
  26. end