我认为这会很有用,至少我觉得有用,我搜索但没有找到任何合适的东西。
假设您有一组使用标准输出的行,或者这些行包含在一个函数中。然后我需要将输出流更改为文件。但不是 diary() 等。
例子:
ShowResults(...) % this is a function containing a lot of fprintf('asdasdasd', ...)
% which by default shows messages on monitor
那么我需要类似的东西:
ShowResults(...) % this will now output to monitor
setOutputHandler(my_file_pointer); % setup redirection
ShowResults(...) % this will now output to the file
setOutputHandler(stdout);
甚至更好的是:
setOutputHandler(stdout, my_file_pointer);
ShowResults(...) % this will now output to the file and monitor at the same time
setOutputHandler(stdout);