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 Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by