App designer: randomly generated sentence GUI
Ältere Kommentare anzeigen
Hello everyone,
I have created a random phrase generator in Matlab; it starts by choosing between two types of sentences (using randi) and then uses randi again to construct one of the two types and displays it in the command window.
I am having, however, hell of a time trying to create a GUI that displays the generated text somewhere. I added a callback to my random phrase generator function and associated it with a button and a textbox; the function runs properly when I press the button but nothing appears in the textbox.
Anyone knows?
I have been looking it up but it seems that the app designer has been changing every year.
2 Kommentare
Mohammad Sami
am 26 Dez. 2019
Can you provide a copy your callback function to see if anything is wrong with it.
Eleanna Kritikaki
am 26 Dez. 2019
Bearbeitet: Stephen23
am 26 Dez. 2019
Akzeptierte Antwort
Weitere Antworten (1)
Image Analyst
am 26 Dez. 2019
Bearbeitet: Image Analyst
am 26 Dez. 2019
Assuming your edit text box is named edtText, try this. First create your sentence however you do it, then:
app.edtText.String = yourSentence; % Set string property, not value property.
Also, your callback for the push button where you create this sentence and send it to the GUI should not have a "clear all" command in it.
4 Kommentare
Eleanna Kritikaki
am 27 Dez. 2019
Image Analyst
am 27 Dez. 2019
You should know that MATLAB is case sensitive. So while I wrote
app.edtText.String = yourSentence; % S in String is UPPER CASE.
you wrote
app.edtText.string = yourSentence; % String all lower case - BAD!
I believe that is the cause of the error.
Eleanna Kritikaki
am 27 Dez. 2019
Mohammad Sami
am 30 Dez. 2019
Good to hear that it works.
I did not notice the clear all.
The reason why it broke your code, is that it will clear the variables passed into your function (app and event). So you will no longer be able to access these variables in the later part of your function. In this case we needed the "app" variable to access the edit text field.
Kategorien
Mehr zu Common Operations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!