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

3 views (last 30 days)
function UITableCellSelection(app, event)
global t
indices = event.Indices;
n=indices(1);
% Information and the Images of the Missiles
if strcmp(t.System{n},"MIM-23A HAWK")
cla(app.UIAxes)
imshow("MIM_23A_HAWK.jpg","Parent",app.UIAxes)
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")
cla(app.UIAxes)
imshow("CAMM.jpg","Parent",app.UIAxes)
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")
cla(app.UIAxes)
imshow("CAMM_ER.jpg","Parent",app.UIAxes)
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 = '';
  2 Comments
Ali Deniz
Ali Deniz on 21 Jun 2022
It gives the error "Unrecognized property 'Text' for class 'matlab.ui.Figure' " . I use Matlab R2019b version. I also tried " app.Label.Value = ''; ". It gives the error "Unrecognized property 'Value' ". Thank you.
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
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;

Categories

Find more on Develop uifigure-Based Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!