in the "label" object draw a rectangle around it

조회 수: 3 (최근 30일)
pipor
pipor 2023년 9월 9일
답변: Rahul 2024년 9월 23일

답변 (1개)

Rahul
Rahul 2024년 9월 23일
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:

카테고리

Help CenterFile Exchange에서 Feature Detection and Extraction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by