Difference between revisions of "Opt disp"

From QETLAB
Jump to navigation Jump to search
(Created page with "{{Function |name=opt_disp |desc=Display a message to the user (sometimes) |upd=December 3, 2012 |v=1.00 |helper=1}} <tt>'''opt_disp'''</tt> is a function...")
 
 
Line 2: Line 2:
 
|name=opt_disp
 
|name=opt_disp
 
|desc=Display a message to the user (sometimes)
 
|desc=Display a message to the user (sometimes)
 +
|cat=[[List of functions#Helper_functions|Helper functions]]
 
|upd=December 3, 2012
 
|upd=December 3, 2012
|v=1.00
+
|v=0.50
 
|helper=1}}
 
|helper=1}}
 
<tt>'''opt_disp'''</tt> is a [[List of functions|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 <tt>if</tt> statements within the code of other functions, thus making them a bit more readable.
 
<tt>'''opt_disp'''</tt> is a [[List of functions|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 <tt>if</tt> statements within the code of other functions, thus making them a bit more readable.
Line 16: Line 17:
 
==Examples==
 
==Examples==
 
Display and don't display a message to the user:
 
Display and don't display a message to the user:
<pre>
+
<syntaxhighlight>
 
>> opt_disp('Hello\n',1)
 
>> opt_disp('Hello\n',1)
 
Hello
 
Hello
 
>> opt_disp('Hello\n',0)
 
>> opt_disp('Hello\n',0)
>>  
+
>>
</pre>
+
</syntaxhighlight>
  
 
==Notes==
 
==Notes==
 
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 [http://www.mathworks.com/help/matlab/ref/disp.html disp] or [http://www.mathworks.com/help/matlab/ref/fprintf.html fprintf] function. Note that <tt>opt_disp</tt> uses <tt>fprintf</tt>, so you may need to end your string with a newline character <tt>\n</tt> (as in the example) for it to function how you expect.
 
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 [http://www.mathworks.com/help/matlab/ref/disp.html disp] or [http://www.mathworks.com/help/matlab/ref/fprintf.html fprintf] function. Note that <tt>opt_disp</tt> uses <tt>fprintf</tt>, so you may need to end your string with a newline character <tt>\n</tt> (as in the example) for it to function how you expect.
 +
 +
{{SourceCode|name=opt_disp|helper=1}}

Latest revision as of 16:08, 29 September 2014

opt_disp
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.

Syntax

  • 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.

Examples

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

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

Notes

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 here to view this function's source code on github.