in the "label" object draw a rectangle around it

3 visualizaciones (últimos 30 días)
pipor
pipor el 9 de Sept. de 2023
Respondida: Rahul el 23 de Sept. de 2024

Respuestas (1)

Rahul
Rahul el 23 de Sept. de 2024
Hi,
Based on the description, I understand that you are trying to create a rectangular solid border around a label object, which can be associated to a ‘uifigure’ in MATLAB or a block label in Simulink. You can refer to the code given below for each case mentioned earlier:
  • Simulink Labels: To draw a rectangle border around a label in a Simulink model, you can add an annotation with the shape of a rectangle programmatically, by adding drop shadow and using “get_params” function to specify the annotation position beneath the respective block.
% Open the model
mdlName = model_name;
blockName = block_name;
load_system(mdlName);
blockPosition = get_param([gcs '/blockName], 'Position');
% Add annotation object
annotation = Simulink.Annotation([gcs], 'Your Label Text');
annotation.DropShadow = 'on';
% Set annotation position and maintain vertical padding
padding = 10;
rectLeft = blockPosition(1);
rectTop = blockPosition(2) + padding;
rectRight = blockPosition(3);
rectBottom = blockPosition(4);
% Place annotation next to block
annotation.Position = [rectLeft rectTop rectRight rectBottom]
  • UI Labels: To create an axis label as an annotation with a solid border, you can use “annotation” function to specify annotation layout, color and text:
% Create a figure
figure;
% Sample plot
plot(1:10);
% Specify position as [x, y, width, height][AA7]
dim = [.5 .4 .8 .5];
% Label Text
str = 'Straight Line Plot from 1 to 10';
% Create annotation object
anno = annotation('textbox',dim,'String',str, 'FitBoxToText','on');
For more information regarding usage of annotation objects in MATLAB & Simulink, refer to the documentation links mentioned below:

Categorías

Más información sobre Feature Detection and Extraction en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by