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 8716211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:01:31+00:00 2026-06-13T06:01:31+00:00

I have mex code that I call from my matlab scripts. To debug the

  • 0

I have mex code that I call from my matlab scripts. To debug the code, I had put a lot of mexPrintf statements, but for timing purposes now I don’t want any I/O taking place in my mex code call (since I/O takes a lot of time). What’s the easiest and best way to suppress the mexPrintf calls in my code, such that those statements are not executed at all, without having to delete/comment out those statements? (I don’t want to delete/comment out those statements and recompile my mex code because I may need these debug statements later on, and I don’t want to keep going through this iteration of modifying and building my code again and again).

Is there any compiler switch that can do the trick? or some preprocessor statement?

Thanks!

  • 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-06-13T06:01:32+00:00Added an answer on June 13, 2026 at 6:01 am

    You can not turn mexPrintf off. You need to modify your code. Define e.g. DEBUG flag to decide, when you want to print things, and when not. For example, with normal printf function

    #include <stdio.h>
    #include <stdlib.h>
    
    //#define DEBUG
    #ifdef DEBUG
    #define MPRINT(...) printf(__VA_ARGS__);
    #else
    #define MPRINT(...)
    #endif
    
    int main()
    {
      MPRINT("%d\n", 5);
    }
    

    Nothing is printed if you run it now. But if you uncomment the #define DEBUG statement, you get 5 printed.

    Alternatively, you can embrace all mexPrintf calls in such clauses:

    #ifdef DEBUG
    mexPrintf(...);
    #endif
    

    Again, nothing will be printed if DEBUG is not defined. But that is much more work.

    You can also do a similar thing without recompiling your mex file by using a normal if statement and pass a verbose parameter to the mex file. However, this will still have some impact on performance if you execute the if statement too often. So go for the DEBUG more – that is the standard way to do it.

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

Sidebar

Related Questions

I have some Matlab code that is run many millions of times as mentioned
I have a bit of code I'm running to test multithreading in MATLAB mex
I am linking some fortran code (f90) from matlab using mex and I am
I have some Matlab code which needs to be speeded up. Through profiling, I've
Hey there, assuming I have the following code in a mex routine: mxArray *newPoint
It is generally very easy to call mex files (written in c/c++) in Matlab
I have noticed that MATLAB provides the BLAS and LAPACK headers among others: $
I have a C++ file that: starts the matlab engine calls matlab_optimize() (a compiled
I have a mex function that takes a double precision input vector, downcasts the
Is there any way to have a mex routine for matlab with opencl C++

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.