How to set a let to display a numerical value in App Design?

38 views (last 30 days)
I recently migrated my gui from guide to app design. Everything was working prior to the move. one last (hopefully) issue i am facing is updating the text on a label to a numberical value returned by numel() function.
error is :
Error using matlab.ui.control.internal.model.mixin.MultilineTextComponent/set.Text (line 49)
'Text' must be a character vector, or a 1-D array of the following type: cell array of character vectors, string, or categorical.
The code :
while strcmp(value,'On')
[plyX, plyY] = ginput(2); %% prompt the user to click two points. (Care needs to be taken to fist click the lower left corner and then select upper right corner)
width = abs(plyX(1) - plyX(2)); %%Compute width
height = abs(plyY(1) - plyY(2)); %%Compute height
rec = rectangle('Position',[plyX(1) plyY(1) width height]);
[in,on] = inpolygon(app.X,app.Y,plyX,plyY);
inon = in | on; %%Ammend point in and on the edge of the rectangle
idx = inon(:); %%get all the indeces of the points in the polygon
% [ptsx get_in]=numpoints(plyX,plyY,laser1_pts); %%using numpoints function just for comparison
xcoord = app.X(idx); %%get the X coordinates of the poits in the polygon
PointsInSelection = numel(xcoord); %%get the number of points
% PointsInSelection2 = get_in; %%get the number of points
app.Label.Text = PointsInSelection;
% display(handles.PointsInSelection2);
pause(3);
delete(rec);
end

Accepted Answer

Adil Ali
Adil Ali on 5 Dec 2019
I used
app.Label.Text = string(numericalValue);
compared to
app.Label.Text = numericalValue;
And it worked!
Not sure why App design had to make things complicated! it is so simple to code without it. Its almost like programming in Java!
  1 Comment
Rik
Rik on 5 Dec 2019
Just like all other parts of Matlab: it matters what the data type is. You can't mix up the value of a variable and the representation of that value in a character vector or string scalar
v1=10;
v2='10';
v3="10";
%all 3 are different (although v2 and v3 are similar in many ways)

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!