comparison Copy_of_multithreshold 1.46/psychometricFunction.m @ 28:02aa9826efe0

mainly multiThreshold
author Ray Meddis <rmeddis@essex.ac.uk>
date Fri, 01 Jul 2011 12:59:47 +0100
parents
children
comparison
equal deleted inserted replaced
27:d4a7675b0413 28:02aa9826efe0
1 % ------------------------------------------------------- psychometricFunction
2 function [psy, levelsBinVector, binFrequencies, nNo, nYes]=...
3 psychometricFunction(levels, responses, psyBinWidth)
4 % computes a psychometric function from rwo vectors (levels and responses)
5 % responses is a binary vectory (1=yes)
6 % psyBinWidth is the bin width (dB) of the output psychometric function
7 % this function is called by both fitPsychometricFunction and subjGUI
8 % for this reason it should notbe bundled with fitPsychometricFunction
9
10 binFrequencies=[]; nNo=[]; nYes=[];
11 if min(levels)+abs(psyBinWidth) < max(levels)
12 % create a set of bins for the psychometric function
13 levelsBinVector= min(levels): abs(psyBinWidth): max(levels);
14 else
15 psy=[]; levelsBinVector=[];
16 return
17 end
18
19 idx0=find(responses==0); % isolate 'no'
20 z=levels(idx0);
21 nNo=hist(z, levelsBinVector);
22
23 idx1=find(responses>0); % isolate 'yes'
24 y=levels(idx1);
25 nYes=hist(y, levelsBinVector);
26
27 if sum(nNo)==0 | sum(nYes)==0
28 psy=[]; levelsBinVector=[];
29 return % yesses and nos required for a function
30 end
31
32 binFrequencies=nNo+nYes;
33
34 warning off MATLAB:divideByZero
35 psy=nYes./binFrequencies; % psy is the proportion of 'yes' responses
36 warning on MATLAB:divideByZero
37 lastwarn('');
38
39 idx=~isnan(psy); %remove empty bins
40 idx=(nYes>0) |(nNo>0); %remove empty bins
41 psy=psy(idx);
42 levelsBinVector=levelsBinVector(idx);
43 binFrequencies=binFrequencies(idx);
44 nNo=nNo(idx);
45 nYes=nYes(idx);
46
47 % [nNo' nYes']
48 % [levelsBinVector' psy']
49 % plot(levelsBinVector,psy,['o'])