Is there a non-eval based solution to effectively getting the output of disp as a string value?
3 次查看(过去 30 天)
显示 更早的评论
x = evalc('disp(''hello world'')');
However, I'd really rather not use eval* functions for a couple of reasons. I imagine that `disp` itself is implemented in terms of the function I'm looking for, even if it is an undocumented function.
4 个评论
Brent Kostich
2020-5-29
What is your purpose behind getting "the string-view of generic MATLAB values"? Chances are there is a way to accomplish your goal without displaying the values.
回答(1 个)
Walter Roberson
2020-5-30
You can use diary() to have the output of disp copied to a file, then turn diary off and read the file. This will not be any better than evalc.
2 个评论
Walter Roberson
2020-5-30
The code for display() does not build up the character representation of complex objects and then afterwards send the character representation to the command window. Instead, the various display() methods build up the output in small pieces, mostly emitting the results as they go. A few of the routines do build up multiple columns and emit that, but at the moment I do not recall anywhere that builds up multiple rows to be emitted together (I could not rule out the possibility at the moment; each datatype is responsible for its own strategy.)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Entering Commands 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!