Code covered by the BSD License  

Highlights from
Command window text

Be the first to rate this file! 6 Downloads (last 30 days) File Size: 1.7 KB File ID: #31438
image thumbnail

Command window text

by Hugh Nolan

 

13 May 2011 (Updated 19 May 2011)

Copies all text in the command window into a cell array of strings.

| Watch this File

File Information
Description

This m-file allows you to export all text in the Command Window to a cell array of strings, each entry being a line of text from the window. The unparsed raw string is also available, if desired.

Operation is very simple - this file looks for the appropriate java object in the root window and gets text from it.

I was looking for a way to do this, particularly for error tracking in some software I maintain, and nobody seemed to have written up this method, so I present it here for you to use.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
FindJObj - find java handles of Matlab graphic objects

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
14 May 2011 Jan Simon

A short method without FINDJOBJ:
cmdDoc = com.mathworks.mde.cmdwin.cmdWinDocument.getInstance;
Str = cmdDoc.getText(1, cmdDoc.getLength);
CStr = regexp(Str, '\n', 'split');
The methods cmdWin.findStringInContent and cmdWin.findStringInContentBackwards can be helpful also to restrict the exported string.
Strange effects are possibe with the insertString method: You can modify former output!

19 May 2011 Hugh Nolan

Thanks Jan - that didn't work exactly as written (version differences? I'm running R2007b) but gave me enough to work it out - updated and faster. Good work!

20 May 2011 Jan Simon

Yes, the com commands depend on the Matlab version. The posted code runs on 2009a.

Please login to add a comment or rating.
Updates
19 May 2011

Removed dependency on findjobj.m - thanks Jan

Tag Activity for this File
Tag Applied By Date/Time
data export Hugh Nolan 13 May 2011 14:42:20
logging Hugh Nolan 13 May 2011 14:42:20
java Hugh Nolan 13 May 2011 14:42:20

Contact us at files@mathworks.com