How to display Chart diagram in a report, using report generator?

4 Ansichten (letzte 30 Tage)
Tommaso
Tommaso am 6 Aug. 2024
Kommentiert: Tommaso am 8 Aug. 2024
Hi,
I have a problem with the visualization of Chart diagram and related properties in my model.
I using this code line (in a matlab script) to search all the subsystem object (including chart):
allsubsysObj = modelObj.find('-isa','Simulink.SubSystem','-or','-isa','Simulink.ModelReference','-depth',1);
The script find the number of element that i'm expected (2 chart and 2 subsytem) but when i tried to put the diagram figure i obtained the inner content of the subsytem and the chart.
auxpara = CenterDiagram(Diagram(allsubsysObj(1)),R);
Cap = Text(strcat("Figure ",num2str(ChCounter),".",num2str(FigCounter),": ",allsubsysObj(1).Name," subsystem"));
Cap.Style = [{FontSize(Str.CapFontSize)},{Color(Str.CapColor)},{Bold(true)},{HAlign(Str.CapAlign)}];
FigCounter = FigCounter + 1;
subsec.add(auxpara);
subsec.add(Cap);
subsec.add(LineBreak());
How i can insert only the top level diagram of the chart?

Antworten (1)

Abhas
Abhas am 6 Aug. 2024
Hi Tommaso,
To visualize only the top-level diagram of a chart in Simulink, you may refer to the below steps:
  1. Use the "get_param" function to retrieve the handle of the chart or subsystem you want to visualize.
  2. Set the "ShowPortLabels" parameter to 'none' to hide the inner contents.
  3. Use the "Simulink.BlockDiagram.createSubsystem" function to capture the diagram as an image.
  4. Insert the captured image into your report.
The following is a sample example to demonstrate the same:
% Get the handle of the chart or subsystem
% Replace 'model_name/Chart' with the actual path to your chart or subsystem
chartHandle = get_param('model_name/Chart', 'Handle');
% Set to show no port labels, which hides inner contents for visualization
set_param(chartHandle, 'ShowPortLabels', 'none');
% Capture the diagram as an image
Simulink.BlockDiagram.createSubsystem(chartHandle);
% Now you can use the captured image in your report
You may refer to the following MathWorks documentation links to have a better understanding of the same:
  1. https://www.mathworks.com/help/simulink/slref/simulink.blockdiagram.createsubsystem.html
  2. https://www.mathworks.com/help/simulink/slref/matlabfunction.html#:~:text=Main-,Show%20port%20labels,-%E2%80%94%20Display%20options
  3 Kommentare
Abhas
Abhas am 7 Aug. 2024
Hi,
Ensure that the model is loaded before trying to access its components. Use the "load_system" function if necessary. Additionally, when using "get_param" to retrieve the handle, ensure that the full path to the chart or subsystem is correct. It should be the path within the Simulink model, not just the name.
Tommaso
Tommaso am 8 Aug. 2024
OK,it works.
But unfortunately this operation change my original model putting a subsystem.
I wish to display only the top level figure of the chart.
Regards

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programmatic Model Editing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by