Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6017941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:12:06+00:00 2026-05-23T03:12:06+00:00

I use anonymous functions for diagnostic printing when debugging in MATLAB. E.g., debug_disp =

  • 0

I use anonymous functions for diagnostic printing when debugging in MATLAB. E.g.,

debug_disp = @(str) disp(str);
debug_disp('Something is up.')
...
debug_disp = @(str) disp([]);
% diagnostics are now hidden

Using disp([]) as a “gobble” seems a bit dirty to me; is there a better option? The obvious (?) method doesn’t work:

debug_disp = @(str) ;

This could, I think, be useful for other functional language applications, not just diagnostic printing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:12:07+00:00Added an answer on May 23, 2026 at 3:12 am

    You could add a regular do-nothing function to your codebase.

    function NOP(varargin)
    %NOP Do nothing
    %
    % NOP( ... )
    %
    % A do-nothing function for use as a placeholder when working with callbacks
    % or function handles.
    
    % Intentionally does nothing
    

    Then you can use a function handle to it instead of to an anonymous function wherever you want to no-op something out.

    debug_disp = @NOP;
    

    Now it’s somewhat self-documenting, making it explicit that you intended to do nothing, instead of grabbed the wrong input for disp(). It will be apparent in the source code, plus, when you’re in the debugger and examining variables holding function handles, it’ll show up as “@NOP”, which may be more readable than an anonymous handle. And you can get a list of all nopped-out operations in the “profile report” output by looking at a list of callers to NOP.

    You could also use Matlab’s built-in @deal, which in the degenerate case does nothing and returns nothing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After discovering lambda expressions, and their use as anonymous functions, I've found myself writing
Anonymous functions are available from PHP 5.3 . Should I use them or avoid
Both Eclipse and NetBeans throw errors about the use of anonymous functions. The error
I'm trying to understand when to use anonymous JavaScript functions. State differences between the
Nearly all my JS files are wrapped in anonymous functions. If I include use
I am not sure when I should use anonymous types instead of local variables
What is the use of anonymous classes in Java? Can we say that usage
I'm attempting to use the following code to serialize an anonymous type to JSON:
Is it possible to use overlapped I/O with an anonymous pipe? CreatePipe() does not
Use case: A does something on his box and gots stuck. He asks B

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.