Commit 9860ff9c authored by Jesse Heckman's avatar Jesse Heckman

major update February

parent 08acb90c
%% PREPARE VARIABLES
%supindex() %provides column info for [M]
[M] = pa_supersac(Sac,Stim);
M_BB = M(M(:,30)<=199,:); % Broadband
M_HP = M(M(:,30)>=200,:); M_HP = M_HP(M_HP(:,30)<=299,:); %Highpass
M_LP = M(M(:,30)>=300,:); % Lowpass
clc;
supindex;
%% CREATE FIGURE - Response(Target)
% Azimuth
y = M_BB(:,8); x = M_BB(:,23);
subplot(2,3,1);
[h,b,r] = pb_regplot(x,y);
title('Azimuth accuracy to BB sounds');
y = M_HP(:,8); x = M_HP(:,23);
subplot(2,3,2); [h,b,r] = pb_regplot(x,y);
title('Azimuth accuracy to HP sounds');
y = M_LP(:,8); x = M_LP(:,23);
subplot(2,3,3); [h,b,r] = pb_regplot(x,y);
title('Azimuth accuracy to LP sounds');
% Elevation
y = M_BB(:,9); x = M_BB(:,24);
subplot(2,3,4); [h,b,r] = pb_regplot(x,y);
title('Elevation accuracy to BB sounds');
y = M_HP(:,9); x = M_HP(:,24);
subplot(2,3,5); [h,b,r] = pb_regplot(x,y);
title('Elevation accuracy to HP sounds');
y = M_LP(:,9); x = M_LP(:,24);
subplot(2,3,6); [h,b,r] = pb_regplot(x,y);
title('Elevation accuracy to LP sounds');
% PB_ANALYSISSACLOC
%
% This script semi-automates your saccade localization analyses.
% PBToolbox (2019): JJH: j.heckman@donders.ru.nl
%% INITIALIZE
% Clear and ready workspace
pb_clean;
cfn = pb_newfig(0);
axis([-60 60 -60 60]);
axis square
hold on;
%%
s = struct([]);
s(end+1).az = -20:10:20;
s(end+1).el = ones(1,length(s(end).az))*30;
s(end+1).az = -30:10:30;
s(end+1).el = ones(1,length(s(end).az))*20;
s(end+1).az = -40:10:40;
s(end+1).el = ones(1,length(s(end).az))*10;
s(end+1).az = -50:5:50;
s(end+1).el = zeros(1,length(s(end).az));
s(end+1).az = -40:10:40;
s(end+1).el = ones(1,length(s(end).az))*-10;
s(end+1).az = -30:10:30;
s(end+1).el = ones(1,length(s(end).az))*-20;
s(end+1).az = -20:10:20;
s(end+1).el = ones(1,length(s(end).az))*-30;
az = [];
el = [];
for i = 1:length(s)
az = [az, s(i).az];
el = [el, s(i).el];
end
scatter(az,el,'filled');
pb_hline;
pb_vline;
pb_nicegraph
%%
ind = 1:63;
ind1 = [1:2:5 6:2:12 13:2:21 23:2:42 44:2:50 53:2:57 60:2:62];
length(ind1)
az1 = az(ind1);
el1 = el(ind1);
% az1 = az(1:2:end);
% el1 = el(1:2:end);
%
% az2 = az(2:2:end);
% el2 = el(2:2:end);
h(1) = plot(az,el,'o');
h(2) = plot(az1,el1,'o');
h(1).MarkerSize = 12;
h(2).MarkerSize = 12;
title('SLC setup Vestibulair Chair');
legend('RZ6a','RZ6b');
ylabel('Position (\epsilon)');
xlabel('Position (\alpha)');
pb_nicegraph
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2019) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......@@ -7,15 +7,16 @@ function draft(obj)
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
% Select/make figure
%% Create figure
% Select parent/make figure
if isempty(obj(1).parent)
for iObj = 1:numel(obj)
obj(iObj).parent = gcf;
end
end
% Set figure
% Set figure settings
set(obj(1).parent,'color','w');
t = sgtitle(obj(1).parent,obj(1).title);
set(t,'FontSize',20);
......@@ -23,34 +24,73 @@ function draft(obj)
ax = gobjects(0);
dsz = size(obj);
%% Super labels
% Check if labels are the same, and prep super labels
lab_x = true; lab_y = true;
for iObj = 1:numel(obj)
if ~strcmp(obj(1).labels.xlab, obj(iObj).labels.xlab); lab_x = false; end
if ~strcmp(obj(1).labels.ylab, obj(iObj).labels.ylab); lab_y = false; end
end
obj(1).labels.supx = lab_x;
obj(1).labels.supy = lab_y;
%% Create (sub)plots
% Draft each subplot
for iObj = 1:numel(obj)
iAx = pb_invidx([dsz(1), dsz(2)],iObj);
iAx = pb_invidx([dsz(1), dsz(2)],iObj);
% Make axes
ax(iAx) = subplot(dsz(1),dsz(2),iObj); % pb_invidx([dsz(1), dsz(2)],iAx)
ax(iAx) = subplot(dsz(1),dsz(2),iObj);
if obj(iAx).pva.subtitle; title(obj(iAx).pva.subtitle); end
axis(obj(iAx).pva.axis);
hold on;
% Plot data
nCol = 1;
if ~obj(iObj).pva.continious
nCol = length(unique(obj(iObj).pva.color));
end
% Plot data
colors = pb_selectcolor(nCol,obj(iAx).pva.def);
uD = unique(obj(iAx).pva.color);
for iCol = 1:nCol
d = obj(iAx).pva;
d.ind = d.color == uD(iCol);
d.color = colors(iCol,:);
for iDP = 1:length(obj(iObj).dplot)
obj(iObj).dplot{iDP}(obj,d);
end
end
% Set proper labels
xlabel(obj(iAx).labels.xlab);
ylabel(obj(iAx).labels.ylab);
% Set labels
if ~obj(1).labels.supx; xlabel(obj(iAx).labels.xlab); end
if ~obj(1).labels.supy; ylabel(obj(iAx).labels.ylab); end
% Make scientific notations on the axes.
ax(iAx).YAxis.Exponent = length(num2str(max(abs(round(ax(iAx).YLim)))))-1;
ax(iAx).XAxis.Exponent = length(num2str(max(abs(round(ax(iAx).XLim)))))-1;
end
%% Adjust axis handles
% Set super labels
% TO DO:
% 1. Optionalize subplots to have squared/linked/fixed axis
% 2. Scale and move axis to make graph nice, pleasing and non-overlapping
make_axes(obj,ax);
make_suplabel(obj);
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% Written by: Jesse J. Heckman (2019) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function draft2(obj)
% PB_DRAFT>DRAFT
%
% OBJ.DRAFT will draw a figure from a pb_draft-object.
%
% See also PB_DRAFT, SET_LABELS, SET_TITLE, SET_GRID, PRINT
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
% Select/make figure
if isempty(obj(1).parent)
for iObj = 1:numel(obj)
obj(iObj).parent = gcf;
end
end
% Set figure
set(obj(1).parent,'color','w');
t = sgtitle(obj(1).parent,obj(1).title);
set(t,'FontSize',20);
ax = gobjects(0);
dsz = size(obj);
% Draft each subplot
for iObj = 1:numel(obj)
iAx = pb_invidx([dsz(1), dsz(2)],iObj);
% Make axes
ax(iAx) = subplot(dsz(1),dsz(2),iObj); % pb_invidx([dsz(1), dsz(2)],iAx)
if obj(iAx).pva.subtitle; title(obj(iAx).pva.subtitle); end
axis(obj(iAx).pva.axis);
hold on;
% Plot data
if ~isempty(obj(iAx).pva.y)
uC = unique(obj(iAx).pva.color);
nc = length(uC);
p = gobjects(0);
col = pb_selectcolor(nc,obj(iAx).pva.def);
% Group data
for iPl = 1:nc
x = obj(iAx).pva.x;
y = obj(iAx).pva.y;
ind = obj(iAx).pva.color == uC(iPl);
p(iPl) = plot(x(ind),y(ind),obj(iAx).pva.ls);
p(iPl).Color = col(iPl,:);
end
end
% Set proper labels
xlabel(obj(iAx).labels.xlab);
ylabel(obj(iAx).labels.ylab);
% Make scientific notations on the axes.
ax(iAx).YAxis.Exponent = length(num2str(max(abs(round(ax(iAx).YLim)))))-1;
ax(iAx).XAxis.Exponent = length(num2str(max(abs(round(ax(iAx).XLim)))))-1;
end
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......@@ -12,7 +12,9 @@ classdef pb_draft < matlab.mixin.Copyable
% Set public properties
properties (Access = public)
h_title
h_legend
h_ax_legend
h_ax_labels
h_ax_plot
results
...
end
......@@ -46,6 +48,7 @@ classdef pb_draft < matlab.mixin.Copyable
end
set_title(obj,title,varargin);
set_legend(obj,varargin);
set_labels(obj,varargin);
set_grid(obj,varargin);
......@@ -53,6 +56,7 @@ classdef pb_draft < matlab.mixin.Copyable
plot_hline(obj,varargin); % plot horizontal lines
plot_vline(obj,varargin); % plot vertical lines
plot_dline(obj,varargin); % plot diagonal lines
plot_bubble(obj,varargin);
stat_regres(obj,varargin); % transform regression
stat_probit(obj,varargin); % transform probit
......@@ -73,7 +77,7 @@ end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% Written by: Jesse J. Heckman (2019) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function plot_bubble(obj,varargin)
% PB_DRAFT>PLOT_RAWDATA
%
% OBJ.PLOT_RAWDATA(varargin) will add plot handle for draft function to object.
%
% See also PB_DRAFT
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
v = varargin;
p.XW = pb_keyval('Xwidth',v);
p.YW = pb_keyval('Ywidth',v);
p.BS = pb_keyval('binsize',v);
p.def = pb_keyval('def',v,5);
obj.dplot = vertcat(obj.dplot,{@(dobj,data)bubble_plot(dobj,data,p)});
obj.results.bubbleplot_handle = {};
end
function h = bubble_plot(~,data,p)
% Bubbleplot
% Select binsizes
if isempty(p.XW); [~,~,p.XW,~] = pb_binsize(data.x); end
if isempty(p.YW); [~,~,p.YW,~] = pb_binsize(data.y); end
if ~isempty(p.BS); p.XW = p.BS; p.YW = p.BS; end
% Hist
X = round(data.x/p.XW) * p.XW;
Y = round(data.y/p.YW) * p.YW;
uX = unique(X);
uY = unique(Y);
[UX,UY] = meshgrid(uX,uY);
x = uY;
TOT = NaN(size(UX));
for ii = 1:length(uX)
sel = X == uX(ii);
r = Y(sel);
N = hist(r,x);
if isscalar(x)
N = histogram(r,[x-Xwidth x+Xwidth]);
end
TOT(:,ii) = N;
end
%% Normalize
TOT = log10(TOT+1);
mxTOT = nanmax(nanmax(TOT));
mnTOT = nanmin(nanmin(TOT));
TOT = (TOT-mnTOT)./(mxTOT-mnTOT);
%% Plot
M = TOT(:);
x = UX(:);
y = UY(:);
sel = M>0;
M = M(sel);
x = x(sel);
y = y(sel);
SZ = ceil(100*M);
[~,~,idx] = unique(M);
col = statcolor(max(idx),[],[],[],'def',p.def);
C = col(idx,:);
h = plot(x,...
y, ...
'Marker', p.marker, ...
'LineStyle',p.ls, ...
'Color',C);
'MarkerFaceColor',C...
'MarkerSize', p.markersz);
end
'Color', data.color, ...
switchpar, ...
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2019) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function plot_dline(obj,varargin)
% PB_DRAFT>PLOT_DLINE
%
% OBJ.PLOT_DLINE(varargin) will add plot handle for draft function to object.
%
% See also PB_DRAFT
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
p.v = varargin;
obj.dplot = vertcat(obj.dplot,{@(dobj,data)dline(dobj,data,p)});
end
function h = dline(~,~,p)
% Plots diagonal line
style = pb_keyval('style',p.v,'k--');
visibility = pb_keyval('visibility',p.v,'off');
h = pb_dline('style',style,'visibility',visibility);
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2019) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function plot_hline(obj,varargin)
% PB_DRAFT>PLOT_DLINE
%
% OBJ.PLOT_DLINE(varargin) will add plot handle for draft function to object.
%
% See also PB_DRAFT
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
p.v = varargin;
obj.dplot = vertcat(obj.dplot,{@(dobj,data)hline(dobj,data,p)});
end
function h = hline(~,data,p)
% Plots horizontal line
type = pb_keyval('type',p.v,'mid');
point = pb_keyval('point',p.v);
style = pb_keyval('style',p.v,'k--');
if isempty(point)
switch type
case 'mid'
point = (min(data.y)+max(data.y))/2;
case 'mean'
point = mean(data.y);
case 'mode'
point = mode(data.y);
end
end
h = pb_hline(point,'style',style);
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2019) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function plot_rawdata(obj,varargin)
% PB_DRAFT>PLOT_RAWDATA
%
% OBJ.PLOT_RAWDATA(varargin) will add plot handle for draft function to object.
%
% See also PB_DRAFT
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
v = varargin;
p.type = pb_keyval('type',v,'line');
p.alpha = pb_keyval('alpha',v,1); %% crashes if you change the alpha to below 1?
p.marker = pb_keyval('marker',v,'o');
p.markersz = pb_keyval('markersz',v,3);
p.ls = pb_keyval('linestyle',v,'none');
p.fcol = pb_keyval('facecolor',v,'fill');
p.col = pb_keyval('color',v,'k');
obj.dplot = vertcat(obj.dplot,{@(dobj,data)rawdata(dobj,data,p)});
obj.results.rawdata_handle = {};
end
function h = rawdata(~,data,p)
% Plots rawdata
switch p.type
case 'dot'
sz = p.sz;
h = scatter(data.x,data.y,ceil(p.markersz/2.5),data.color,'filled','MarkerFaceAlpha',p.alpha); %% crashes if you change the alpha to below 1?
case 'line'
if strcmp(p.fcol,'fill'); switchpar = data.color; else; switchpar = 'none'; end
h = plot(data.x(data.ind), ...
data.y(data.ind), ...
'Color', data.color, ...
'Marker', p.marker, ...
'LineStyle',p.ls, ...
'MarkerFaceColor',switchpar, ...
'MarkerSize', p.markersz);
otherwise
end
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2019) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function plot_vline(obj,varargin)
% PB_DRAFT>PLOT_VLINE
%
% OBJ.PLOT_VLINE(varargin) will add plot handle for draft function to object.
%
% See also PB_DRAFT
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
p.v = varargin;
obj.dplot = vertcat(obj.dplot,{@(dobj,data)vline(dobj,data,p)});
end
function h = vline(~,data,p)
% Plots vertical line
type = pb_keyval('type',p.v,'mid');
point = pb_keyval('point',p.v);
style = pb_keyval('style',p.v,'k--');
if isempty(point)
switch type
case 'mid'
point = (min(data.x)+max(data.x))/2;
case 'mean'
point = mean(data.x);
case 'mode'
point = mode(data.x);
end
end
h = pb_vline(point,'style',style);
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2019) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......@@ -43,7 +43,7 @@ end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% Written by: Jesse J. Heckman (2019) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function make_axes(obj,ax,varargin)
% PB_DRAFT>SET_LEGEND
%
% OBJ.SET_LEGEND(varargin) rescale, size and store axes handles..
%
% See also PB_DRAFT
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
obj(1).h_ax_plot = ax;
% TODO: LINK AXES AND FIND OPTIMAL AXE TICKS
positions = zeros(length(ax),4);
for iAx = 1:length(ax)
positions(iAx,:) = ax(iAx).Position(:);
end
obj(1).labels.ypos = min(positions(:,2));
obj(1).labels.xpos = min(positions(:,1));
obj(1).labels.pos = [min(positions(:,1))/1.33 min(positions(:,2))/1.33 max(positions(:,1)+positions(:,3)) max(positions(:,2)+positions(:,4))];
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2019) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function make_suplabel(obj,varargin)
% PB_DRAFT>MAKE_SUPLABEL
%
% OBJ.SET_LEGEND(varargin) Make superlabels handle.
%
% See also PB_DRAFT
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
x = pb_keyval('x',varargin,obj(1).labels.supx);
y = pb_keyval('y',varargin,obj(1).labels.supy);
pos = pb_keyval('position',varargin,obj(1).labels.pos);
slax = gobjects(0);
if x || y
slax = axes('Units','Normal','Position',pos,'Visible','off','tag','suplabel'); % TODO: HOW TO MAKE THE POSITION ADAPTING ON AXES/FIGURE?
if x; xlabel(obj(1).labels.xlab,'Visible','on'); end
if y; ylabel(obj(1).labels.ylab,'Visible','on'); end
obj(1).h_ax_labels = slax;
end
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2019) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......@@ -8,19 +8,36 @@ function parse_va(obj,varargin)
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
%% READ DATA
% Read Data, and set keyvals
v = varargin;
pva.x = pb_keyval('x',v,[]);
pva.y = pb_keyval('y',v,[]);
pva.z = pb_keyval('z',v,[]);
pva.def = pb_keyval('def',v,1);
pva.color = pb_keyval('color',v,ones(length(pva.x),1));
pva.axis = pb_keyval('axis',v,'square');
pva.subtitle = pb_keyval('subtitle',v);
pva.x = pb_keyval('x',v,[]);
pva.y = pb_keyval('y',v,[]);
pva.z = pb_keyval('z',v,[]);
pva.ls = pb_keyval('linespec',v,'o');
pva.def = pb_keyval('def',v,2);
pva.color = pb_keyval('color',v,ones(length(pva.x),1));
pva.axis = pb_keyval('axis',v,'square');