Giving a button a numeric value in app designer
Mostra commenti meno recenti
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 Commenti
Walter Roberson
il 16 Mag 2020
app.TotalCaloriesTextArea.Value = ...
string(app.TotalCaloriesTextArea.Value{1}) + event.Source.Text;
Note that if you want a space between the number and the previous text then use + " " after the first part.
Michael Clopton
il 16 Mag 2020
Modificato: Michael Clopton
il 16 Mag 2020
Walter Roberson
il 16 Mag 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);
Risposte (0)
Categorie
Scopri di più su Desktop in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
