Filter löschen
Filter löschen

Giving a button a numeric value in app designer

2 Ansichten (letzte 30 Tage)
Michael Clopton
Michael Clopton am 16 Mai 2020
Kommentiert: Walter Roberson am 16 Mai 2020
I was trying to create a button that would add a numeric value to text area so far I can't seem to get it to work, my code so far is
% Button pushed function: BananaButton
function BananaButtonPushed(app, event)
app.TotalCaloriesTextArea.Value =
[app.TotalCaloriesTextArea.Value{1} event.Source.Text];
end
end
  3 Kommentare
Michael Clopton
Michael Clopton am 16 Mai 2020
Bearbeitet: Michael Clopton am 16 Mai 2020
I appreciate the response, i'm trying to create a calorie counter app. I want each button to add the calories to a text area. I think I may be using the wrong codes.
Walter Roberson
Walter Roberson am 16 Mai 2020
It seems to me that you would want to test to see if the text area is empty, and if so initialize to 0 and otherwise pull out the text area value. (You are using app designer so I gather that text areas can be configured as numeric.) Then add the values, and write into the text area.
Something like
app.TotalCaloriesTextArea.Value = ...
app.TotalCaloriesTextArea.Value{1} + event.Source.Text;
or perhaps
app.TotalCaloriesTextArea.Value = ...
app.TotalCaloriesTextArea.Value{1} + str2double(event.Source.Text);

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by