Cannot run a word-stimulus perception experiment
2 次查看(过去 30 天)
显示 更早的评论
Hi, below are three function scripts for my sample experiment. I've tried using a number stimulus which works perfectly, however I am getting no luck with four-letter word stimuli. When the word stimulus is supposedly to appear on the screen, only the first letter is shown. Then it is waiting for an input. I type the letter that was shown but there is no response. PLEASE HELP!! There's probably something wrong in my function scripts that I'm not seeing.
function[info_array] = collect_info()
prompt={'Number:','Name:','Age:'};
dlg_title = 'Participant info';
num_lines = 1;
%default value for number; we usually do not have a default name
defAns = {'1','',''};
info_array = inputdlg(prompt,dlg_title,num_lines,defAns);
function [accuracy_est] = word_perception(time_var)
%%%clear command window
clc
%%%design and save stimuli
V = ['farm'; 'door'; 'book'; 'tree'];
stimulus_file = 'stimulus_list.txt';
dlmwrite(stimulus_file,V);
%%%preallocate memory for subject responses
W=NaN(4,1);
%%%collect and save subject info
[info_array] = collect_info;
info_subject_file = 'subject_info.mat';
save(info_subject_file,'info_array')
%%%run experiment
for i = 1:size(V,1)
%%%display stimulus for specified interval time_var (in seconds)
stim = V(i,1);
disp(stim)
pause(1)
clc
%%%collect response
[user_output] = req_wordinput;
W(i,1) = user_output;
end
clc
%%%store response
response_file = 'response_list.txt';
dlmwrite(response_file,W);
%%%compute accuracy
accuracy_est = mean(V==W);
function[output_word] = req_wordinput()
valid_input = 0;
while~valid_input
display_message = ':';
output_word = input(display_message);
if ischar(output_word) & isequal(size(output_word),[1 1])
valid_input = 1;
else display ('Invalid input. Please try again!')
pause(1)
end
end
0 个评论
采纳的回答
更多回答(1 个)
Walter Roberson
2015-11-4
编辑:Walter Roberson
2015-11-4
stim = V(i,1); extracts the first element of the i'th row of V. Character strings are implemented as row vectors of characters, so they have only one row and the first element of the row is the first character in the string.
In your input routine you have
if ischar(output_word) & isequal(size(output_word),[1 1])
which would succeed if output_word was a single character and would not match otherwise. You obtain output_word as
output_word = input(display_message);
In MATLAB, input() accepts characters until the user presses return (or enter). When only one parameter is passed to input (the message to display), input() then more or less executes the entered value as a command and returns the output of the command. If the user had entered a non-numeric letter (and then pressed enter), input() would attempt to find a variable or function that matched that name and return its value rather than returning the character that the user entered. If you were to instead pass two parameters to input with the second one being 's' as in input(display_message, 's') then input will return the actual characters typed, as a character string, rather than trying to execute the characters as a command.
You might want to look at the File Exchange contribution http://www.mathworks.com/matlabcentral/fileexchange/7465-getkey
You should also be changing req_wordinput() to take as input the number of characters the user should enter.
2 个评论
Walter Roberson
2015-11-4
In that time frame, you should just change
output_word = input(display_message);
to
output_word = input(display_message, 's');
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Entering Commands 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!