3

I have read several posts here and in other forums to understand how to do hide the output of a function on the command window. Generally, the answer is: "use evalc".

Today I posted another question for a different issue (Memory issue with Matlab: update variable in .mat) and a user showed me why it is always better to avoid the usage of eval/evalc (How to put these images together?).

What if I want to avoid evalc but I want to hide the output of a function from the command windows? Is it possible to do it?

EDIT:

I don't think it is a duplicate.

As said in the introduction there are several posts (also here in stack overflow) that address this question. But (including the post which should be a duplicate of this question: Suppressing a function's command window output ) the main answer is to use evalc, which as written in the title, I don't want to use. Also, as written in the link above, using a private disp might be risky, it is not going to suppress outputs resulting from fprintf or from a missing semicolon (creating also a private fprintf would hide also some output string that I want to have).

Community
  • 1
  • 1
merch
  • 945
  • 8
  • 19
  • 3
    "Don't use eval ever" is a statement I don't agree with, unfortunately the MATLAB language is not perfect. You should avoid eval whenever **possible**, but there are few cases where it is simply not possible. During the past 5 years I have been a software developer primarily programming in Matlab. There have been 2 cases where I had to use eval, one was the case you described. Sometimes you simply have to accept the disadvantages of `eval`. I am not aware of any better solution and not seeing any better answer in the duplicate question I think there is no better solution. – Daniel Feb 17 '16 at 17:01
  • The issue is that I should call with eval a very computationally expansive function, which I don't want to slowdown. If there are no chance to do it without eval, I'd prefer to not hide the output. However, given that I am looking for a solution different than the one you posted, could you please remove the "duplicate" tag? If there are no other ways for doing it, I will close the question myself. – merch Feb 17 '16 at 17:08
  • What specific function are you using that spits its output to the Command Window? Generally such behavior is a sign of a poorly-coded function. Can you not create a version that avoids the calls to `disp`/`fprintf`? – horchler Feb 17 '16 at 17:18
  • @fipelle: Now it seems you now have a new more specialized question applying the solution using a private `fprintf`. I recommend to ask a new question. Mention that you are aware of `evalc` and don't want to use it for performance reasons. Also give a example how you use `fprintf` to produce your string outputs (don't understand that, I would use `sprintf`). I recommend to simply ask a new question, then it is open immediately and you don't have to wait for me or someone else to reopen. – Daniel Feb 17 '16 at 17:20
  • 1
    Ok, thank you, I will open a new question this evening – merch Feb 17 '16 at 17:24

0 Answers0