how to clear label area in each if/elseif loop ?

3 views (last 30 days)
function UITableCellSelection(app, event)
global t
indices = event.Indices;
% Information and the Images of the Missiles
if strcmp(t.System{n},"MIM-23A HAWK")
MsgString = {'Raytheon tarafından geliştirilen sistem'};
WrapString=textwrap(MsgString, 70);
uilabel(app.UIFigure,"Text",WrapString,"Position",[531 17 368 279])
elseif strcmp(t.System{n},"CAMM")
MsgString = "Common Anti-air Modular Missile - CAMM ya da deniz ortamında kullanılan Sea Ceptor";
WrapString=textwrap(MsgString, 70);
uilabel(app.UIFigure,"Text",WrapString,"Position",[531 17 368 279])
elseif strcmp(t.System{n},"CAMM-ER")
MsgString = "Orta menzilli karatabanlı hava savunma ";
WrapString=textwrap(MsgString, 65);
uilabel(app.UIFigure,"Text",WrapString,"Position",[531 17 368 279])
When I select the CAMM-ER after the CAMM, the texts in the label text area is shown like that. How can I clear the label text area before the second information? Thank you.

Answers (2)

Image Analyst
Image Analyst on 21 Jun 2022
Can't you just do
app.UIFigure.Text = '';
Image Analyst
Image Analyst on 3 Jul 2022
If your static text label is not called UIFigure, then use the actual name of the static text label or edit text field. Let's say the one edit text field near Guidance is called edtGuidance. Then do
app.edtGuidance.Text = 'blah blah blah whatever';

Sign in to comment.

Voss on 3 Jul 2022
Calling uilabel creates a new label component. Any other label components that already exist are unaffected by the creation of a new label. Therefore, if you want the new label component to replace the old one(s), you would delete the old one(s) when the new one is created.
However, you can avoid having to do all that by using one label the whole time and just update its Text property when needed:
app.Label.Text = WrapString;

Community Treasure Hunt

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

Start Hunting!