MATLAB GUI table and input

3 views (last 30 days)
Yusuf Oguzhan Turgut
Yusuf Oguzhan Turgut on 9 Jun 2019
Hello, I am trying to create a GUI from an existed code below. I have several questions.
close all
clear all
clc
% % % delete Statistics2.mat
% % % Statistics2=[];
% % % save('Statistics2.mat','Statistics2');
%reset(RandStream.getDefaultStream,sum(100*clock));
reset(RandStream.getGlobalStream,sum(100*clock));%updates the seed for generating random numbers
allNumbers=0;%1 for practicing only numbers, 0 for practicing non-letter characters
SymbolsShift={'"' '!' char(39) '^' '+' '%' '&' '/' '(' ')' '=' '?' '_'};% the non-letter characters by pressing shift
SymbolsAltGr={'@' '#' '$' '{' '[' ']' '}' char(92)};% the non-letter characters by pressing alt-gr
SymbolsNormal={'*' '-'} ;% the non-letter characters by pressing one button above the keyboard
SymbolsDown={'<' '>' '.' ':' '|'};% the non-letter characters by pressing one button below the keyboard
SymbolsNumber={'1' '2' '3' '4' '5' '6' '7' '8' '9' '0'};% the numbers for practicing
%%% allSymbols=[SymbolsShift SymbolsAltGr SymbolsNormal SymbolsDown SymbolsNumber];
if allNumbers==1
allSymbols=[SymbolsNumber];% practicing only numbers
else
allSymbols=[SymbolsShift SymbolsAltGr SymbolsNormal SymbolsDown];% practicing non-letter characters other than numbers
end
alpha1=0.7;%weight for accuracy in efficiency calculation
alpha2=0.3;%weight for speed in efficiency calculation
M=5;%number of characters in each query
%N=100;
N=15;%total number of characters in each experiment
CorrectlyTyped=0;%the number of correctly typed characters in each experiment
tic
k=0;%number of characters up to that point
while k<N
% actual=allSymbols{ii};
actualCell=allSymbols([floor(length(allSymbols)*rand(M,1))+1]);%chooses M random non-letter characters
% % % % actualCell={char(92) char(92) char(39) char(39) char(92)};
actualMat=cell2mat(actualCell);%converts the cell of M non-letter characters to matrix
backSlashes=find(actualMat==char(92));%detects the indices of '\' because it is reserved for other purposes
kk=1;%the index for each character in a query
forScreen=[];% the double type matrix for the characters in a query
for jj=1:M %for each character in a query
if ismember(jj,backSlashes)%if the character is a backslash
forScreen(kk:kk+1)='\\'; % we should modify '\' to '\\' because '\' is reserved for other purposes
kk=kk+2;
else
forScreen(kk)=actualMat(jj);% if it is not a backslash copy the character to forScreen
kk=kk+1;
end
end
% % % % fprintf([forScreen '\n']);
% % % % answer='55555';
% % % % disp(answer)
answer=input(['Write the following character sequence: \n' forScreen '\n Your answer is the following: \n'] ,'s');% prompt for typing the characters in forScreen
disp('----------------------------------------------')%draws a horizontal line to distinguish each query
if length(answer)~=M
disp('Wrong number of characters!')%the number of characters typed for each query should be equal to M
else
k=k+M;
for ii=1:M
if strcmp(actualCell(ii),answer(ii))==true % compares each typed character to the character in query
CorrectlyTyped=CorrectlyTyped+1;%if they coincide increment number of correctly typed characters
end
end
end
end
elapsedTime=toc;
if k==N
load Statistics2 % load the statistics which contains accuracy, speed and efficiency for each experiment
Statistics2=[Statistics2 [CorrectlyTyped/N;elapsedTime/N;CorrectlyTyped/N/2*2*alpha1+1/(elapsedTime/N)*2*alpha2]];%updates statistics
disp(' Accuracy Speed Efficiency')% title for all experiments
SS=size(Statistics2);
LL=SS(2);%Number of experiments
fprintf('Experiment %d: %6.2f %6.2f %6.2f \n',[1:LL;Statistics2])%Convert the statistics data to table format
save('Statistics2.mat','Statistics2');% saves the statistics after incorporating the latest experiment
clear Statistics2;
end
done=1;
This code gives random 5 nonletter characters to user, and user will enter the same. Also the code gives 3 datas : the time that user spend on entering the input, checking all 5 characters are same with user's input and creates an efficiency ratio from time and correction . Also it saves the datas in Statistics2.mat table for each experiment. Here is an output example.
Write the following character sequence:
#{|}.
Your answer is the following:
#{|}
----------------------------------------------
Wrong number of characters!
Write the following character sequence:
!!&}{
Your answer is the following:
!!!!!
----------------------------------------------
Write the following character sequence:
/}|[{
Your answer is the following:
!!!!!
----------------------------------------------
Write the following character sequence:
-%>!\
Your answer is the following:
!!!!!
----------------------------------------------
Accuracy Speed Efficiency
Experiment 1: 0.67 2.97 0.67
Experiment 2: 0.73 2.63 0.74
Experiment 3: 0.80 2.10 0.85
My questions are
1 ) In my GUI, the user enters input in just above box of the start and check button, after clicking on start button. In check Button,
i) I want to get the user's input, check the similarity with MATLAB's 5 random characters (5 boxes under the blue box)
ii) I want to show this statistics2.mat table on my GUI after the part i. How can I do that ? (After the code checks the input similarities, measured time, calculated the efficiency, it will press the statistics2.mat table on yellow part.)
  2 Comments
Rik
Rik on 9 Jun 2019
You should use a function instead of clear all;close all;clc.
Because input is asking the user for input in the command prompt, you shouldn't be using it in a GUI. Retrieve the String property of your text field instead.
Word to the wise: don't use GUIDE to build your GUI. It will resutl in code that is hard to understand and maintain. Use AppDesigner instead, or use my small guide to avoid GUIDE:
  • Make a figure (with f=figure;) and look into the doc for figure which properties you want to turn off (you probably want to set Menu and Toolbar to 'none')
  • Create buttons and axes and everything you need with functions like uicontrol and axes. Save the handles to each element to fields of a struct (like handles.mybutton=uicontrol(___);)
  • When you've finished loading all data (and saving it to fields of your handles struct), and creating all the buttons, save your handles struct to the guidata of your figure like this guidata(handles.f,handles);. (You can also use getappdata and setappdata)
  • You can set the Callback property of many objects. If you do, use a function name with an @ in front, or a char array that can be evaluated to valid code. (like @MyFunction or 'disp(''you pushed the button'')')
  • Callback functions will be called with two arguments: the first is a handle to the callback object, the second is eventdata that may contain special information. To get access to your data, just use handles=guidata(gcbo);. You can replace the gcbo function with the name of the first input to your callback function if you prefer.
  • More information about callbacks can be found in multiple places in the doc, for example here.
Yusuf Oguzhan Turgut
Yusuf Oguzhan Turgut on 9 Jun 2019
Thank you very much but I cannot enough time to redesign it. But I understood. It's more quick.

Sign in to comment.

Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!