How can I set a numeric value in a Label? App Designer

조회 수: 8 (최근 30일)
José Mario Valdeolivar Acosta
José Mario Valdeolivar Acosta 2019년 5월 24일
답변: Abhishek 2025년 4월 29일
G'day and how can I set a numeric value in a Label? I was doing a program that calculates the maxima and minima of a polynomial function (the program also graphs the function tho) and I already wrote the code for that but how can I set the numerical value of the Maxima and Minima in a Label? I'm using App designer. And thank you for helping me.

답변 (1개)

Abhishek
Abhishek 2025년 4월 29일
Hi @José Mario Valdeolivar Acosta,
To display values such as "fMax" and "fMin" in the labels (as shown in the screenshot) first there is a need to convert these numeric values into strings. This can be done using the “sprintf()’ function. Once you have converted the numbers to text, simply assign this string to the label’s “Text” property.
Here is the step-by-step process:
  1. First you need to identify the labels. This can be done by checking out the names in the Component Browser in App Designer.
  2. After calculating “fMin” and “fMax”, convert the numeric values to string values and assign them to the labels in this way:
app.MaxLabel.Text = sprintf('Max: (%.2f, %.2f)', xMax, fMax);
app.MinLabel.Text = sprintf('Min: (%.2f, %.2f)', xMin, fMin);
The numerical display precision can be adjusted by modifying the format specifier within the “sprintf()” function. For example, altering the value in '%.2f' changes the number of decimal places to two places.
Please refer to the documentations for more details:
Hope this helps.

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by