Programmatically add annotation with an equation to simulink
Mostrar comentarios más antiguos
Hey all,
I'm trying to add an annotation to a Simulink model which includes an equation using Latex syntax. However, all I get is the plain text.
latexString = 'x = \frac{1}{2}'
h = Simulink.Annotation(gcs, latexString);
How exactly do I do this?
Thanks!
Respuestas (2)
Bhavana Ravirala
el 13 de Feb. de 2023
Editada: Bhavana Ravirala
el 13 de Feb. de 2023
Hi Cedric,
To add a Latex equation to a Simulink annotation, you need to use the Latex interpreter by setting the 'Interpreter' property of the annotation object to 'latex'. Refer the code below:
latexString = 'x = \frac{1}{2}';
h = Simulink.Annotation(gcs, latexString);
set(h, ' Description', 'latex');
You can also use the function ‘pslinkfun’ to programmatically add annotations to a block in a model.
Please refer to the documentation below for more information.
Hope this helps!!
1 comentario
Cedric Kotitschke
el 13 de Feb. de 2023
Hi, I use this approach:
notePath = "Subsystem/BlockName"; % Replace it with the path to your annotation
Text = "$\text{Description:}\\\frac{a}{b}$" % This is the text displayed in the annotation
richText = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0//EN' 'http://www.w3.org/TR/REC-html40/strict.dtd'><html><head><meta name=""qrichtext"" content=""1""/><style type=""text/css"">p, li { white-space: pre-wrap; }</style></head><body align=""left"" style="" font-family:'Helvetica'; font-size:10px; font-weight:400; font-style:normal;""><p align=""left"" style="" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;""><math style=""font-size:10px;"">" + Text + "</math></p></body></html>";
Position = [0 0 20 20]; % Specify the location
% Finaly create the annotation
h = add_block('built-in/Note', notePath, ...
'Interpreter', 'rich', ...
'Text', richText, ...
'Position', Position);
Then you get a tex formated annotation.
Categorías
Más información sobre Simulink Environment Customization en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!