Effacer les filtres
Effacer les filtres

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

22 vues (au cours des 30 derniers jours)
Adil Ali
Adil Ali le 5 Déc 2019
Commenté : Rik le 5 Déc 2019
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

Réponse acceptée

Adil Ali
Adil Ali le 5 Déc 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 commentaire
Rik
Rik le 5 Déc 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)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by