Displaying randomized texts in app designer (GUI)
4 views (last 30 days)
Show older comments
Hello, If you look in the comments. I have also attached my code and a screen shot of what the GUI currently looks like.
I have made an editfield, with different examples of what the text should look like, but the only thing appearing on that tab is the list box. it should be a randomization(from the text i have included in the code) for what text is displayed.
2:
How would i connect the values from the listbox to the actual text (There will be 4 text in total, i am using the randperm to randomize which one is dispalyed on GUI, but only one of those is the correct answer).
I stated that i already have a list box with "YES" and "NO". 3 of the text will always be wrong so the answer should always be NO and 1 will always be right, so the answer should always be YES.
What i am trying to say is ' if the wrong text is displayed and the user anwsers "YES" instead of "NO". How do i tag that as incorrect answer? and vice versa.
I have also attached my code.
Thanks in Advance.
6 Comments
Jiri Hajek
on 29 Nov 2022
Your question is not so much about MATLAB, but about an algorithm. There are a great mant ways to do what you want. Starting from where you are, you could perhaps make use of the following MATLAB functions to achieve your goal:
- callback function on your answers, where you could check the user;s choice
- in that callback, you can use the isequal function to compare the displayed string with the correct answer
- Display the answer by assigning a value to the text property of an answering text field
Answers (1)
Divyanshu
on 23 Feb 2023
The possible workaround for the issue faced is you can have an edit field which indicates “correct” or “incorrect” to the App-user depending upon the response. And you can “disable” or “enable” the Next button depending upon the value of response indicating field.
Here is a demo App which demonstrates the same->
Note: I have written logic which is going to randomly display one of the three sentences -> [“How are you?", "Hi Jane", "Please call me”].
And the correct response is -> “Hi Jane”
Here is the code-view of the demo App->
methods (Access = private)
% Code that executes after component creation
function startFunctn(app)
sentenceList = ["How are you?" "Hi Jane" "Please call me"];
index = randi(3);
app.SentencementioneintheAudioyoujustheardTextArea.Value = sentenceList(index);
set(app.NextButton,'Enable','off');
app.check();
end
% Value changed function: ListBox
function check(app, event)
app.StatusofyourResponseEditField.Value = "";
value = app.ListBox.Value;
if(value == "Yes" && app.SentencementioneintheAudioyoujustheardTextArea.Value == "Hi Jane")
app.StatusofyourResponseEditField.Value = "Correct";
elseif(value == "No" && app.SentencementioneintheAudioyoujustheardTextArea.Value ~= "Hi Jane")
app.StatusofyourResponseEditField.Value = "Correct";
else
app.StatusofyourResponseEditField.Value = "Incorrect";
end
if(app.StatusofyourResponseEditField.Value == "Correct")
set(app.NextButton,'Enable','on');
else
set(app.NextButton,'Enable','off');
end
end
end
0 Comments
See Also
Categories
Find more on Downloads in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!