tags:

views:

275

answers:

4

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 HTML (or some other markup) from MATLAB? Or am I stuck writing to a file and opening a browser?

+4  A: 

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]);

alt text

gnovice
+1 -- interesting... not what i'm looking for, but i'll file it away for future reference.
Jason S
+3  A: 

Use the Java Swing component inside a MATLAB figure, precisely JEditorPane using MATLAB's javacomponent() function. JEditorPane supports a good subset of HTML.

alt text

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,

Mikhail
+1 -- thanks! -
Jason S
A: 

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.

Jason S
If you don't want to write to a file you can use the text:// protocol. web('text://<html><body>My html text...</body></html')
Mike Katz
+6  A: 

You can display the HTML text in a PopupPanel as explained here: http://UndocumentedMatlab.com/blog/customizing-help-popup-contents/

alt text

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/

alt text

Yair Altman
Yair, nice to see you at StackOverflow
Mikhail