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!