Is there a non-eval based solution to effectively getting the output of disp as a string value?

조회 수: 5 (최근 30일)
The related question has an answer:
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
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.
Brandon Barker
Brandon Barker 2020년 5월 29일
편집: Brandon Barker 2020년 5월 29일
The goal is to use the C Engine API to display such output (output of arbitrary MATLAB values that is); when using the C engine API, the output of such functions is not used on stdout, but I can get the output of MATLAB function calls.
A lot of languages that have some notion of a way to get such a canonical string view, though in some languages, not all objects are supported. I guess Java Objects might be one such instance in MATLAB. Python has the 'repr' function for instance, and Haskell has the 'show' function for types that have an instance of the Show typeclass.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
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
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.)
Brandon Barker
Brandon Barker 2020년 6월 1일
Thanks Walter, that's interesting to know. As for diary, I'm aware of it and have recently used it with the MATLAB Engine for general logging purposes.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by