Write text to web browser including carriage returns.

24 views (last 30 days)
The following code displays a function saving the resulting text as a character array and attempts to display the result.
test=evalc('type readbmp');
str=strcat('text://<html>',test,'</html>')
web(str)
If I simply >>type readbmp, I get lines with carriage returns. If I display the character string via >>test, I get lines with carriage returns. But when I open the character string in the work space or use the web command, I get just one long unreadable character string.
I want to use these commands programmatically in a Live Script with long functions displayed outside a Live Script. How might I do this? Using a web browser seemed the simplist option rather than trying to create some gui window.

Answers (1)

Hitesh
Hitesh about 14 hours ago
You need to use "strrep" function which will replace newline character (newline) in the captured text with HTML line break tags (<br>), preserving the line breaks in the web display. After that while concatenating the string use the <pre> tag which will preserves both spaces and line breaks. Please refer to the following code:
% Evaluate and capture the contents of 'readbmp'
test = evalc('type readbmp');
% Replace newline characters with HTML line breaks
test_html = strrep(test, newline, '<br>');
% Concatenate the HTML formatted string
str = strcat('text://<html><body><pre>', test_html, '</pre></body></html>');
% Open the formatted string in a web browser
web(str);
For more information regarding the "strrep" function, kindly refer to the below MATLAB documentation:

Products


Release

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!