Assigning randomized values (of a linspace range using randperm) to an empty vector for posterior graphing?

4 views (last 30 days)
Hello, The following code plays two beeps with a pause between them. The pause may vary within a range defined by linspace. Then randperm, randomizes the pauses. What 'c' does is combine both the functions mentioned before, in some sort of indexing device (pardon my novice-ness). When the programme ends, c displays the last randomized duration value of the range .
What I need is to graph all the user's inputs in a graph that compares them with the duration values. The problem is that when 'c' is plotted, it only shows the last duration value, as a small point in the graph.
The thing is supposed to measure the user's timing perception based on the comparison of his inputs and the duration values. It is a neuroscience experiment.
Code:
Fs=8192; %sample rate
y=sin(2*pi*2000*[0:1/Fs:0.5]); %sinewave; rate
a=linspace(0.5,1,5); %pause durations
for b=randperm(5)
c=a(b) %pause's randomization by permutation
sound(y,Fs), pause(c), sound(y,Fs), %sound production
pause,tic, pause, toc %user input; timing measures
end
I hope I was clear enough. Thanks

Accepted Answer

bym
bym on 6 Jul 2012
I have modified your code, see if this is what you are after:
clc;clear
Fs=8192; %sample rate
y=sin(2*pi*2000*[0:1/Fs:0.5]); %sinewave; rate
a=linspace(0.5,1,5); %pause durations
k = 0;
for b=randperm(5)
k = k+1; % counter
c(k) = a(b); %pause's randomization by permutation
sound(y,Fs), pause(c(k)), sound(y,Fs), %sound production
pause
tic
pause
p(k)= toc; % user input; timing measures
pause % extra pause to ensure subject is ready
end
plot(c,p,'bo',c,c,'g-')
xlim([.4 1.1])
ylim([.4 1.1])
xlabel('actual')
ylabel('percieved')
legend('response','ideal',2)
r = corrcoef(c,p);
text(.95,.6 ,num2str(r(2)))

More Answers (1)

Image Analyst
Image Analyst on 6 Jul 2012
Seems like you're looking for the "scatter" function. It plots a scatterplot of one variable, like the user's inputs, against the other variable, like the duration values. Give that a try.

Categories

Find more on Behavior and Psychophysics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!