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

22 次查看(过去 30 天)
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

采纳的回答

Adil Ali
Adil Ali 2019-12-5
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 个评论
Rik
Rik 2019-12-5
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)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by