Diary is not saving all outputs

8 views (last 30 days)
Ali Komai
Ali Komai on 4 Aug 2018
Commented: Ali Komai on 7 Aug 2018
Outputs from the mainscript with fprintf and disp are not saved in the diary BUT if this outputs come from a function they are saved. Is there an option to make the diary also save outputs from the mainscript?
  2 Comments
Jan
Jan on 4 Aug 2018
What is a "main script"? Can you post some code which reproduces the observation?
Ali Komai
Ali Komai on 6 Aug 2018
Edited: Ali Komai on 6 Aug 2018
With main script I mean the actual main program calling all my functions. If I just have a script: diary on disp('Hallo)' diary off
In this script the "Hallo" is not saved in the diary. But if the display command is within a function it will be saved in the diary. I would like to know if there is an easy way to make text outputs (like the "Hello" above that are saved in the diary. Or even easier, I would like ALL output to the command window (no matter if it is an error message or a text output with display or fprintf) saved to a file. The diary function is just saving some but not all.
I run a program that I compiled and deployed to a computer I have not access to all the time, so I need this log file for later debugging. Now it happens sometimes that the program is stopped with a matlab error but there is nothing in the diary. Also it would be convenient if I could make text outputs that are saved at certain points in my program so it will be easier for me to see "how far" the program went before exiting with an error.

Sign in to comment.

Accepted Answer

Jan
Jan on 6 Aug 2018
I'm using a dedicated function for this job. At first this function can open some "channels" for the output, e.g. the command windows and/or files. Afterwards I call this function for all output instead of disp or fprintf. Errors are caught by try/catch, such that there is no output of my code, which is not handles by this specific output function.
It is a lot of work to adjust the complete code to such an output function. But it is worth to have the complete power over where is written what, instead of relying on diary, which has some limitations in your case.
If you are working in the Matlab environment, not in a compiled application, you can use FileExchange: CmdWinTool to get the complete text of Matlab's command window:
Str = CmdWinTool('getText')

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!