DISPLAYING HTML OUTPUT USING MATLAB
Introduction
Matlab is a great tool for technical computing. For each computation we need to display the output and in most of the case the output is displayed in the console. But what if more flexibility is needed? What if we need to display data in tables or in more attractractive manner? We can do this using matlab web browser and the web command along with the text: protocol.
Commands
web
web http://asadujjaman.wordpress.com
web(‘text://<html><body>Hello world!</body> </html>’);
Prerequisite HTML knowledge
HTML is the language of the web. I assume that you already know what html is.
Now I show how to create a table in HTML:

The result is the following table:
| Header1 | Header2 |
|---|---|
| Data1 | Data2 |
The <tr> tag specifies a row, <th> specifies a header cell and <td> specifies an ordinary cell.
The Idea
We can exploit the web(‘text://<html>…</html> ’) command and our html knowledge to display html output in the matlab browser. We produce an HTML string as our computation proceeds and then pass the string to the browser.
A Numerical Example
Last week we solved the problem of computing the roots of a function using a numerical method called SIMPLE FIXED-POINT ITERATION in our computer lab (RUET). We needed to show results of each iteration. We just used disp(sprintf(‘…’ )). But I searched for something more pleasurable. And there is no doubt that I found some satisfactory idea.
The Code

Download SimpleFPI.m
Using the function
Suppose we need to find the roots of f(x) = 0 where, f(x) = e-x-x.
We arrange this in x=g(x) format and g(x) becomes e-x or exp(-x).
The SimpleFPI function takes three arguments:
The function g(x), maximum approximate error (ea) and maximum number of iterations in case the function doesn’t converge.
It outputs two results:
The root and an HTML string describing the process.
From MATLAB
>>> [root, html]=SimpleFPI(‘exp(-x)’,.001,100);
>>>web(sprintf(‘text://%s’,html));
The Output
| i | xi | εa(%) |
|---|---|---|
| 0.000000 | 0.000000 | 100.000000 |
| 1.000000 | 1.000000 | 100.000000 |
| 2.000000 | 0.367879 | 171.828183 |
| 3.000000 | 0.692201 | 46.853639 |
| 4.000000 | 0.500474 | 38.309147 |
| 5.000000 | 0.606244 | 17.446790 |
| 6.000000 | 0.545396 | 11.156623 |
| 7.000000 | 0.579612 | 5.903351 |
| 8.000000 | 0.560115 | 3.480867 |
| 9.000000 | 0.571143 | 1.930804 |
| 10.000000 | 0.564879 | 1.108868 |
| 11.000000 | 0.568429 | 0.624419 |
| 12.000000 | 0.566415 | 0.355568 |
| 13.000000 | 0.567557 | 0.201197 |
| 14.000000 | 0.566909 | 0.114256 |
| 15.000000 | 0.567276 | 0.064752 |
| 16.000000 | 0.567068 | 0.036739 |
| 17.000000 | 0.567186 | 0.020831 |
| 18.000000 | 0.567119 | 0.011816 |
| 19.000000 | 0.567157 | 0.006701 |
| 20.000000 | 0.567135 | 0.003800 |
| 21.000000 | 0.567148 | 0.002155 |
| 22.000000 | 0.567141 | 0.001222 |
The root is 0.567145
Conclusion
This is the very basic approach. More advanced technique like CSS can be used for better flexibility.



