Everything to String? How the simple MATLAB script “seemore” can cure the curse of the console.
For about 50 years programmers had learned to love their monospaced console output. For log files, debugging output or even regular results hardly anything could seriously challenge the text console as the primary output of choice. However, a new feature in recent versions of Google’s Chrome browser should serve as a wake up call to the ASCII purists. This document highlights the innovation in Chrome and introduces the simple script “seemore” to bring this idea to the MATLAB console.
The Chrome console
Everything to String? Chrome’s logging output is far more flexible than the Firefox console. The displayed output can dynamically change its level of detail.
The MATLAB console
The console output of MATLAB has a little recorgnized feature that makes it possible to get more out of the console than pure text. MATLAB can interpret certain HTML inspired link tags that perform arbitrary commands when clicked. This feature can be used to display partial output, that expands at the user’s request. The basic layout of a MATLAB function that presents interactively expanding data can be seen here:
X= eye(5); fprintf('<a href="matlab:X">5x5 matrix, click to expand</a>\n')
We can continue to build our interactive data with consecutive data refinement. Consider the following function f that formats 5 elements of a matrix, followed by a link to show more.
X= eye(5); f= @(x) [mat2str(x(1:5)), '<a href="matlab:disp(f(', mat2str(x(6:end)), '))">show more</a>']; disp(f(X))
Type “seemore” to see more
A particularly annoying short coming of MATLAB’s console is lacking support for the display of structs. Internal structures of MATLAB do heavily rely on structs to store complex input data. Yet, the on-screen serialization into strings runs into the dilemma of showing the right level of detail. Thetaris has developed a simple tool called “seemore”. This tool uses the above tricks to adaptively uncover the information in structs without opening distracting new windows. Everything is nicely integrated into your console.
The screenshots below demonstrate the effect of “seemore” when applied to a nested structure returned by MATLAB’s “lasterror” command. By default MATLAB does not show the nested content of the subfield named “stack”. With “showmore” this shortcomming is resolved. The user can click and drill into the result as needed.
The “seemore” command can either be called without arguments to work on the latest output from your console, or present an adaptive display of any variable in your workspace. Try it out now!
MATLAB’s console has a nice feature to format links, which execute arbitrary commands when clicked. This feature can be used to output data onto the console and allow users to define their level of detail as needed. This can save significant amounts of programming time. You no longer need to retype or adjust commands only to define your output format. Save your time for more creative work.
Unfortunately, the presented feature does not allow us to make the data collapse, after it has expanded. Additionally, the expanded data will always show at the bottom of the command screen, rather than integrating nicely into the structured output view. So there is lots of work left for The MathWorks improving the MATLAB console experience.
The suggested use of the console is obviously not limited to MATLAB. After Chrome has taken the lead, the race is open to modernize the console. With HTML as a standard format this idea could be applied to every log file, every debug output and every result file.