Displaying randomized texts in app designer (GUI)

4 次查看(过去 30 天)
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 个评论
Jiri Hajek
Jiri Hajek 2022-11-29
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
Nwasinachi
Nwasinachi 2022-11-29
编辑:Nwasinachi 2022-11-29
Hello,
I have created the call backs, made an array of sentences to be displayed, randomized that array.
Created a correct and incorrect variable, that will check the anwsers based on a strcmp, but the problem now is i dont know if the correct and incorrect variables are working properly.
This is the code
if strcmp(app.wordarray (1),app.TextArea7_2.Value) && strcmp(app.ListBox2.Value,'YES');
app .Correct = app.Correct+1;% a loop where if this option is displayed and YES is selected from list box then the response is correct
else app.Incorrect = app.Incorrect+1;
end
These are variables in the startfcn
%attempt for text area Question 1
app .Correct=0;
app.Incorrect=0;
firstopt = 'The boy went to school'; % will change text and number of the
Secoption = 'The man went to church';
thoption = 'The girl is going there';
app.wordarray = {firstopt Secoption thoption};
app.TextArea7_2.Value = app.wordarray{randi(numel(app.wordarray))}; %% randomization works.
This is the public property
properties (Access = public)
wordarray % Description
Correct
Incorrect
end

请先登录,再进行评论。

回答(1 个)

Divyanshu
Divyanshu 2023-2-23
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

类别

Help CenterFile Exchange 中查找有关 Downloads 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by