Commit 9dd168c0 authored by Jesse Heckman's avatar Jesse Heckman

update draft

parent ea3bb8fa
No preview for this file type
function pb_vCheckServo
function pb_vCheckServo(waitbool)
% PB_VCHECKSERVO()
%
% PB_VCHECKSERVO() ...
......@@ -7,7 +7,9 @@ function pb_vCheckServo
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
answer = questdlg('Please enable Servo before you continue...','Continue');
if waitbool
questdlg('Please enable Servo before you continue...','Continue');
end
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......
......@@ -42,7 +42,7 @@ function pb_vRunExp(handles)
nTrials = length(block(iBlck).trial);
handles = pb_updatecount(handles,'trial','reset');
[profile,dur] = pb_vSignalVC(handles);
pb_vInitBlock();
pb_vCheckServo(~ismac && ~debug);
% start recording
pb_startLSL(ses);
......@@ -50,8 +50,6 @@ function pb_vRunExp(handles)
% start vestibular chair
if ~ismac && ~debug
pb_vCheckServo;
vs = pb_sendServo(profile);
blockTime = tic;
pb_startServo(vs);
......@@ -101,19 +99,18 @@ function pb_vRunExp(handles)
Dat(iBlck).pupil_labs = str(2).read;
Dat(iBlck).optitrack = str(3).read;
Dat(iBlck).block_info = handles.block(iBlck);
pb_vStoreData(handles.cfg, Dat);
% update block information
handles.cfg = pb_updatecount(handles.cfg,'block','count');
end
end
%% CHECK OUT
% finalizes experiment, and resets handles.
% check out experiment
pb_vEndExp;
pb_vStoreData(handles.cfg, Dat);
pb_vInitialize(handles, false);
pb_delobj(ses, rc, str);
toc(expTime);
end
......
......@@ -74,7 +74,7 @@ function pb_vVestExp(varargin)
block(9).Vertical = struct('Amplitude', 20, 'Signal', 3, 'Duration', BD, 'Frequency',.1);
block(10).Horizontal = struct('Amplitude', 0, 'Signal', 3, 'Duration', BD, 'Frequency',.1);
block(10).Vertical = struct('Amplitude', 25, 'Signal', 3, 'Duration', BD, 'Frequency',.1);
block(10).Vertical = struct('Amplitude', 20, 'Signal', 3, 'Duration', BD, 'Frequency',.1);
%% Save data somewhere
writeexp(expfile,datdir,block);
......
function obj = draft(obj)
% OBJ.DRAFT()
function draft(obj)
% PB_DRAFT>DRAFT
%
% DRAFT() ...
% OBJ.DRAFT will draw a figure from a pb_draft-object.
%
% See also PB_DRAFT
% See also PB_DRAFT, SET_LABELS, SET_TITLE, SET_GRID, PRINT
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
% If no parent was given we use the current figure
% 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
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......
classdef pb_draft < matlab.mixin.Copyable
% PB_DRAFT
%
% d = pb_draft creates a instance of a DRAFT figure.
% d = pb_draft creates a instance of a DRAFT object.
%
% See also ...
% See also DRAFT
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
......@@ -11,16 +11,24 @@ classdef pb_draft < matlab.mixin.Copyable
% Set public properties
properties (Access = public)
title = [];
h_title
h_legend
results
...
end
% Set protected properties
properties (Access=protected,Hidden=true)
parent = [];
parent = [];
pva
labels
% title
title = '';
title_O = {};
subtitle = '';
subtitle_O = {};
...
end
%% Methods
......@@ -30,21 +38,32 @@ classdef pb_draft < matlab.mixin.Copyable
% Constructor function
function obj = pb_draft(varargin)
set_title(obj);
...
% read and parse varargin
parse_va(obj,varargin{:});
end
obj = create_figure(obj,fig)
obj = draft(obj);
set_title(obj,title,varargin);
set_labels(obj,varargin);
set_grid(obj,varargin);
plot_hline(obj,varargin);
plot_vline(obj,varargin);
plot_dline(obj,varargin);
stat_regres(obj,varargin); % transform regression
stat_probit(obj,varargin); % transform probit
fit_ellipse(obj,varargin); % make ellipse fit
fit_sigmoid(obj,varargin); % make sigmoidal fit
fit_polyn(obj,varargin); % make polynomial fit
draft(obj); % make plot
print(obj,varargin); % make file
function obj=set_parent(obj,parent)
function obj = set_parent(obj,parent)
obj.parent = parent;
...
end
end
...
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......
function print(obj,varargin)
% PB_DRAFT>PRINT
%
% OBJ.PRINT will print a plot from the draft-figure.
%
% See also PB_DRAFT
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
v = varargin;
h = pb_keyval('h',v,obj(1).parent);
cdir = pb_keyval('cdir',v,[pb_datadir 'PhD' filesep 'Figures' filesep 'Figs' filesep]);
fn = pb_keyval('fn',v,defaultname(cdir));
fit = pb_keyval('fit',v,'-bestfit');
format = pb_keyval('format',v,'-dpdf');
disp = pb_keyval('disp',v,false);
figure(h);
loc = [cdir fn];
print(fit,loc,format);
if disp
open([loc '.' format(3:end)]);
end
end
function fn = defaultname(cdir)
% Find first available filename
cnt = 1;
fn = 'default_f';
hcd = cd;
cd(cdir);
while exist([fn num2str(cnt) '.pdf'],'file')
cnt = cnt+1;
end
fn = [fn num2str(cnt)];
cd(hcd);
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function parse_va(obj,varargin)
% WRITETITLE()
%
% WRITETITLE() ...
%
% See also ...
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
v = varargin;
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');
pva.subtitle = pb_keyval('subtitle',v);
obj.pva = pva;
obj.labels.xlab = '';
obj.labels.ylab = '';
end
\ No newline at end of file
function obj = set_title(obj, title)
function set_labels(obj,varargin)
% WRITETITLE()
%
% WRITETITLE() ...
......@@ -7,8 +7,12 @@ function obj = set_title(obj, title)
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
v = varargin;
labels.xlab = pb_keyval('x',v,'');
labels.ylab = pb_keyval('y',v,'');
obj.title = title;
obj.labels = labels;
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......
function obj = set_title(obj)
function set_title(obj,title,varargin)
% WRITETITLE()
%
% WRITETITLE() ...
......@@ -7,8 +7,8 @@ function obj = set_title(obj)
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
title = 'Default Title';
obj.title = title;
obj(1).title = title;
obj(1).title_O = varargin;
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......
%% Example code 'draft'
pb_clean;
load example_data;
% construct
d(1,1) = pb_draft('x',cars.Displacement,'y',cars.Weight,'color',cars.Cylinders,'def',8,'subtitle','Color1');
d(1,1).set_labels('x','Displacement','y','Weight');
% d(1,2) = pb_draft('x',cars.Displacement,'y',cars.Weight,'color',cars.Cylinders,'def',9,'subtitle','Color2');
% d(1,2).set_labels('x','Displacement','y','Weight');
%
% d(1,3) = pb_draft('x',cars.Displacement,'y',cars.Weight,'color',cars.Cylinders,'def',10,'subtitle','Color3');
% d(1,3).set_labels('x','Displacement','y','Weight');
% d(2,1) = pb_draft('x',cars.Displacement,'y',cars.Weight,'color',cars.Cylinders,'def',4,'subtitle','Color4');
% d(2,1).set_labels('x','Displacement','y','Weight');
%
% d(2,2) = pb_draft('x',cars.Displacement,'y',cars.Weight,'color',cars.Cylinders,'def',5,'subtitle','Color5');
% d(2,2).set_labels('x','Displacement','y','Weight');
%
% d(2,3) = pb_draft('x',cars.Displacement,'y',cars.Weight,'color',cars.Cylinders,'def',6,'subtitle','Color6');
% d(2,3).set_labels('x','Displacement','y','Weight');
%
% d(3,1) = pb_draft('x',cars.Displacement,'y',cars.Weight,'color',cars.Cylinders,'def',7,'subtitle','Color4');
% d(3,1).set_labels('x','Displacement','y','Weight');
%
% d(3,2) = pb_draft('x',cars.Displacement,'y',cars.Weight,'color',cars.Cylinders,'def',8,'subtitle','Color5');
% d(3,2).set_labels('x','Displacement','y','Weight');
%
% d(3,3) = pb_draft('x',cars.Displacement,'y',cars.Weight,'color',cars.Cylinders,'def',9,'subtitle','Color6');
% d(3,3).set_labels('x','Displacement','y','Weight');
d.set_title('Car Data');
d.draft;
d.print('disp',true);
% plotting order is wrong?
\ No newline at end of file
function invidx = pb_invidx(arr,idx)
% PB_INVIDX
%
% PB_INVIDX(arr, idx) calculates reverse array indexing (useful for subplotting).
%
% See also SUBPLOT, PB_DRAFT, DRAFT.
% PBToolbox (2019): JJH: j.heckman@donders.ru.nl
sz = arr;
c = mod(idx,sz(2)); if c==0; c = sz(2); end
r = floor(idx/sz(2))+1-(idx/sz(2)==floor(idx/sz(2)));
invidx = sub2ind(sz,r,c);
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2019) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment