MATLAB: displaying markup (HTML or other format)
I'd like to display a table from a script in MATLAB. I can easily generate the <td>
and other HTML elements, but as far as I know, I can only write them to a file.
Is there a way to display HTM开发者_运维技巧L (or some other markup) from MATLAB? Or am I stuck writing to a file and opening a browser?
You can display the HTML text in a PopupPanel as explained here: http://UndocumentedMatlab.com/blog/customizing-help-popup-contents/
Or in an integrated browser control that points to your HTML file or HTML text as explained here: http://UndocumentedMatlab.com/blog/gui-integrated-browser-control/
Use the Java Swing component inside a MATLAB figure, precisely JEditorPane
using MATLAB's javacomponent()
function. JEditorPane supports a good subset of HTML.
Here is a code sample:
mytext = '<html><body><table border="1"><tr><th>Month</th><th>Savings</th></tr><tr><td>January</td><td>$100</td></tr></table></body></html>';
hfig = figure();
je = javax.swing.JEditorPane( 'text/html', mytext );
jp = javax.swing.JScrollPane( je );
[hcomponent, hcontainer] = javacomponent( jp, [], hfig );
set( hcontainer, 'units', 'normalized', 'position', [0,0,1,1] );
%# Turn anti-aliasing on ( R2006a, java 5.0 )
java.lang.System.setProperty( 'awt.useSystemAAFontSettings', 'on' );
je.putClientProperty( javax.swing.JEditorPane.HONOR_DISPLAY_PROPERTIES, true );
je.putClientProperty( com.sun.java.swing.SwingUtilities2.AA_TEXT_PROPERTY_KEY, true );
je.setFont( java.awt.Font( 'Arial', java.awt.Font.PLAIN, 13 ) );
EDIT: see the discussion of this solution here,
One alternative is to display the table in a graphics window using the UITABLE control.
EDIT: Even though this is only an alternative (not a solution) to the problem in the question, I thought I'd include a sample for anyone who may be interested in this option:
hFigure = figure('Position',[100 100 300 220]);
hTable = uitable(hFigure,'Data',rand(10,3),...
'ColumnName',{'X' 'Y' 'Z'},...
'Position',[20 20 260 180]);
I ended up doing what I didn't quite want to do, namely to write HTML to a file. It requires me to open it in a browser and refresh every time I run my script, but that's not too bad for what I needed in the short term.
精彩评论