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

采纳的回答

Thorsten
Thorsten 2015-11-4
编辑:Thorsten 2015-11-4
stim = V(i,:);
To be more flexible you can use cells to store words of different length:
V = {'me' 'you' 'others'};
stim = V{i};
  1 个评论
Kevin Lai
Kevin Lai 2015-11-4
Thank you!!! I tried out with using the cell format and now it partially works with showing the whole word as stimulus. However, I still cannot continue to the next word. For example, my first word is farm. I see the stimulus, type farm and press enter. However it shows this:
:farm
Error using input
Undefined function or variable 'farm'.
Error in req_wordinput (line 5)
output_word = input(display_message);
Error in word_perception (line 29)
[user_output] = req_wordinput;

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
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 个评论
Kevin Lai
Kevin Lai 2015-11-4
THank you for your explanation Walter, but I am still a bit confused. I really need this problem solved within the next hour or so. Can you perhaps show me in more detail how I should write that, say if I followed Thorsten's way in putting my word stimuli in cell array format
Walter Roberson
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 CenterFile Exchange 中查找有关 Entering Commands 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by