Format (size, color) of output text generated by script in publish() or export()

15 views (last 30 days)
Hello together,
i have several simulation runs with devinded parameters in excel. The results of the simulation are postprocessed with some calculations and figures. I want to publish (or export if a live script works better) the figures and calculation results. The get an readable document i want to format the output. For example a headline for every simulation run with larger font size. The contend of the headline will be created from the parameters defined in a excel sheet.
Thank you in advance
  1 Comment
Florian Schindler
Florian Schindler on 7 Sep 2023
function_options.format='html';
function_options.evalCode=true;
function_options.showCode=false;
publish(("test.m"),function_options);

Sign in to comment.

Answers (1)

Riya
Riya on 7 Sep 2023
Hello Florian Schindler,
As per my understanding, you want to get a formatted readable output document.
Please note that, you can use the ‘publish’ function which generates a view of the specified MATLAB code file and output in an HTML format that can be used for sharing. It saves the HTML file and a file for each graphic that the code creates in a subfolder named html. The location of the html subfolder is relative to the location of file.
When using the `publish` or `export` functions in MATLAB to generate a document from your script, you can format the output text by using HTML markup tags.
Here is an example of how you can format the output text with different sizes and colors:
% Simulation parameters from Excel
simulation_parameters = readtable('simulation_parameters.xlsx'); % Assuming you have the parameters in an Excel file
% Loop over each simulation run
for i = 1:size(simulation_parameters, 1)
% Get the parameters for the current simulation run
parameters = simulation_parameters(i, :);
% Create a headline for the simulation run
headline = sprintf('<h2 style="font-size: 18px; color: blue;">Simulation Run %d</h2>', i);
% Print the headline
disp(headline);
% Perform calculations and generate figures for the current simulation run
% ...
% Your code here
% Print the calculation results
fprintf('<p style="font-size: 12px;">Calculation Result: %f</p>', calculation_result);
% Generate and display figures
% ...
% Your code here
% Print a line break between simulation runs
fprintf('<hr>'); % Horizontal line
% Save figures to file if needed
% ...
% Your code here
end
In this example, the headline for each simulation run is created using the `<h2>` HTML tag with a font size of 18 pixels and blue color. The calculation results are printed using the `<p>` HTML tag with a font size of 12 pixels. You can modify the font sizes, colors, and other CSS properties as needed.
By using HTML markup tags in this way, you can format the output text generated by your script when publishing or exporting it to a document format.
For more information about ‘publish’ function you can refer the following link:
https://www.mathworks.com/help/matlab/ref/publish.html?s_tid=doc_ta
You can provide more details or a minimal reproducible example to further investigate the problem.
I hope it helps!
  1 Comment
Florian Schindler
Florian Schindler on 7 Sep 2023
Thank you for your replie,
what you are descriping is exactly what i am searching for, but i dont get formated output. The html file shows the html code as text
i have added my trail with your example to my Question

Sign in to comment.

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!