필터 지우기
필터 지우기

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

조회 수: 22 (최근 30일)
Adil Ali
Adil Ali 2019년 12월 5일
댓글: Rik 2019년 12월 5일
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