Commit 333d9975 authored by Jesse Heckman's avatar Jesse Heckman

Major update draft + minor update vPrime/tdt

parent 9852da0e
a1 = [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21];
a2 = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 21];
a3 = [0 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20];
a4 = [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21];
a5 = [0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 9];
a6 = [0 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2];
a7 = [0 0 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9];
a8 = [0 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2];
A = [a1;a2;a3;a4;a5;a6;a7;a8];
%Connects to RZ6 #1 via Optical Gigabit
RP=actxcontrol('RPco.x',[5 5 26 26]);
if RP.ConnectRZ6('GB',1)
e='connected'
else
e='Unable to connect'
end
RP.LoadCOF('U:\##BIOFYSICA\#P075 Moving sound\SetTagV_Matrix_test2.rcx');
RP.Run;
if RP.WriteTagVEX('STM_Data', 0, 'F32', A)
e='WriteTagVEX OK'
else
e='WriteTagVEX error'
end
Matrix = RP.ReadTagVEX('STM_Data',0,22,'F32','F64',8)
function draft(obj)
% PB_DRAFT>DRAFT
%
% OBJ.DRAFT will draw a figure from a pb_draft-object.
% OBJ.DRAFT will draw a figure from a draft object.
%
% See also PB_DRAFT, SET_LABELS, SET_TITLE, SET_GRID, PRINT
% See also PB_DRAFT
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
% PBToolbox (2019): JJH: j.heckman@donders.ru.nl
%% Initialize Draft
% Make figure, select parents, and set layouts
......@@ -18,32 +18,24 @@ function draft(obj)
end
% Set figure settings
set(obj(1).parent,'color','w');
t = sgtitle(obj(1).parent,obj(1).title);
set(t,'FontSize',18);
set(obj(1).parent,'Color',[1 1 1]);
set(obj(1).parent,'renderer','painters');
ax = gobjects(0);
objsz = size(obj);
%% Super labels
% Check and prepare superlabels
%% Draft Layout
% Assert and prepare legend, and suplabels
% Check labels
bool = true; if numel(obj) == 1; bool = false; end
lab_x = bool; lab_y = bool;
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
% Set superlabels
obj(1).labels.supx = lab_x;
obj(1).labels.supy = lab_y;
obj.make_legend;
obj.make_suplabel;
obj.make_axes; % CURRENTLY WORKING ON MAKE PLOTS
%% DONE TILL HERE!!! REST NEEDS FIXING!
%% Set Compare Axis
% Check and set comparing axis
ax = gobjects(0);
objsz = size(obj);
nCmp = length(unique(obj(1).pva.axcomp.feature));
if min(objsz) > 1; nCmp = 1; end
......@@ -63,9 +55,9 @@ function draft(obj)
cObj = (iObj-1)*nCmp + iCmp;
% Make Axes
Ax = pb_invidx(objsz.*cmpsz,cObj); % reverse get axes index
Ax2Obj = pb_invidx(objsz,iObj); % reverse get object index
ax(Ax) = subplot(objsz(1)*cmpsz(1),objsz(2)*cmpsz(2),cObj); % make axis
Ax = pb_invidx(objsz.*cmpsz,cObj); % reverse get axes index
Ax2Obj = pb_invidx(objsz,iObj); % reverse get object index
ax(Ax) = subplot(objsz(1)*cmpsz(1),objsz(2)*cmpsz(2),cObj); % make axis
if obj(iObj).pva.subtitle; title(obj(Ax2Obj).pva.subtitle); end
axis(obj(Ax2Obj).pva.axis);
......@@ -95,13 +87,6 @@ function draft(obj)
ax(Ax).XAxis.Exponent = length(num2str(max(abs(round(ax(Ax).XLim)))))-1;
end
end
%% Adjust Axis Handles
% Set super labels
obj.make_legend;
obj.make_axes(ax);
obj.make_suplabel;
end
......
function draft(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
%% Initialize Draft
% Make figure, select parents, and set layouts
% Select parent/make figure
if isempty(obj(1).parent)
for iObj = 1:numel(obj)
obj(iObj).parent = gcf;
end
end
% Set figure settings
set(obj(1).parent,'color','w');
t = sgtitle(obj(1).parent,obj(1).title);
set(t,'FontSize',18);
ax = gobjects(0);
objsz = size(obj);
%% Super labels
% Check and prepare superlabels
% Check labels
bool = true; if numel(obj) == 1; bool = false; end
lab_x = bool; lab_y = bool;
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
% Set superlabels
obj(1).labels.supx = lab_x;
obj(1).labels.supy = lab_y;
%% Set Compare Axis
% Check and set comparing axis
nCmp = length(unique(obj(1).pva.axcomp.feature));
if min(objsz) > 1; nCmp = 1; end
cmpsz = [1 1];
[~,cmpInd] = max(cmpsz);
cmpsz(cmpInd) = nCmp;
cmpsz = fliplr(cmpsz);
obj(1).h_ax_plot.sz = cmpsz .* size(obj);
%% Create Plots
% Draft each subplot
for iObj = 1:numel(obj)
% Repeat for comparing axis
for iCmp = 1:nCmp
cObj = (iObj-1)*nCmp + iCmp;
% Make Axes
Ax = pb_invidx(objsz.*cmpsz,cObj); % reverse get axes index
Ax2Obj = pb_invidx(objsz,iObj); % reverse get object index
ax(Ax) = subplot(objsz(1)*cmpsz(1),objsz(2)*cmpsz(2),cObj); % make axis
if obj(iObj).pva.subtitle; title(obj(Ax2Obj).pva.subtitle); end
axis(obj(Ax2Obj).pva.axis);
hold on;
% Select data
features = unique(obj(1).pva.axcomp.feature);
sel = obj(1).pva.axcomp.feature == features(iCmp);
D = obj(Ax2Obj).pva;
D.x = D.x(sel);
D.y = D.y(sel);
D.color = D.color(sel);
% Plot all graphs
for iDP = 1:length(obj(iObj).dplot)
obj(iObj).dplot{iDP}(obj,D);
end
% Set labels
if ~obj(1).labels.supx; xlabel(obj(Ax2Obj).labels.xlab); end
if ~obj(1).labels.supy; ylabel(obj(Ax2Obj).labels.ylab); end
% Make scientific notations on the axes.
ax(Ax).YAxis.Exponent = length(num2str(max(abs(round(ax(Ax).YLim)))))-1;
ax(Ax).XAxis.Exponent = length(num2str(max(abs(round(ax(Ax).XLim)))))-1;
end
end
%% Adjust Axis Handles
% Set super labels
obj.make_legend;
obj.make_axes(ax);
obj.make_suplabel;
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2019) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
\ No newline at end of file
......@@ -5,7 +5,7 @@ classdef pb_draft < matlab.mixin.Copyable
%
% See also DRAFT
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
% PBToolbox (2019): JJH: j.heckman@donders.ru.nl
%% Properties
......
function make_axes(obj,ax,varargin)
function make_axes(obj,varargin)
% PB_DRAFT>MAKE_AXES
%
% OBJ.MAKE_AXES(varargin) rescale, size and store axes handles..
% OBJ.MAKE_AXES(varargin) make, scale, size and store axes handles.
%
% See also PB_DRAFT
% PBToolbox (2019): JJH: j.heckman@donders.ru.nl
linkaxes(ax,'xy');
positions = zeros(length(ax),4);
%% Initialize
% Obtain axes data
% Get legend data
h = pb_fobj(gcf,'Tag','legend');
scale = [h.Position(1) 1];
sz = obj(1).h_ax_plot.sz;
szfl = fliplr(sz);
opObj = ax(1).OuterPosition(3:4)*scale(1);
% Assess playground
playground = obj(1).h_ax_plot.playground;
objsz = size(obj);
% Assess axcompare
nCmp = length(unique(obj(1).pva.axcomp.feature));
if min(objsz) > 1; nCmp = 1; end
cmpsz = [1 1];
[~,cInd] = max(cmpsz);
cmpsz(cInd) = nCmp;
cmpsz = fliplr(cmpsz);
graphsz = cmpsz .* objsz;
ngraph = prod(graphsz);
%% Build Playground
% Set graphing axes
h = gobjects(ngraph,1);
% h = pb_fobj(gcf,'Tag','legend');
% scale = [h.Position(1) 1];
% sz = obj(1).h_ax_plot.sz;
% szfl = fliplr(sz);
% opObj = ax(1).OuterPosition(3:4)*scale(1);
nAx = length(ax);
for iAx = 1:nAx
cAx = pb_invidx(sz,iAx); % align axes and objects
ax(cAx);
for iAx = 1:ngraph
%% DONE TILL HERE!!! REST NEEDS FIXING!
% ASSIGN AXES TO POSITION RELATIVE TO PLAYGROUND AND INDEX
pos = [0.1+(iAx/20) 0.3 0.3 0.3];
cAx = pb_invidx(graphsz,iAx); % align axes and objects
h(cAx) = axes('Parent',obj(1).parent,'OuterPosition',pos);
axis square
% Scale for legend
if obj(1).h_ax_legend.bool
[xN,yN] = pb_mod(iAx,sz(2)); if xN == 0; xN = sz(2); end
N = [xN,yN+1];
spacing = [];
for iDir = 1:2
width = ax(cAx).OuterPosition(2+iDir);
spacing(iDir) = (scale(iDir)-(width*szfl(iDir)))/(szfl(iDir)+1);
if iDir == 1; ax(cAx).OuterPosition(1) = (N(1)-1)*width + N(1)*spacing(iDir); end
if iDir == 2
if spacing(2)>spacing(1)*1.5
spacing(2) = spacing(1)*1.5;
end
margin = (1-(sz(1)*width + (sz(1)-1)*spacing(2)))/2*1.1;
ax(cAx).OuterPosition(2) = 1-margin-(N(2)*width) - (N(2)-1)*spacing(iDir);
end
end
ax(cAx).OuterPosition(3:4) = opObj;
end
% Set Limits
if obj(1).pva.setAxes
xlim(ax(cAx),obj(1).pva.limits.x);
ylim(ax(cAx),obj(1).pva.limits.y);
end
% Set Grids
setAx = ax(cAx);
if obj(1).grid.bool
f = obj(1).grid.features;
setAx.Box = f.Box;
setAx.TickDir = f.TickDir;
setAx.TickLength = f.TickLength;
setAx.XMinorTick = f.XMinorTick;
setAx.YMinorTick = f.YMinorTick;
setAx.YGrid = f.YGrid;
setAx.XGrid = f.XGrid;
setAx.YColor = f.YColor;
setAx.XColor = f.XColor;
setAx.FontSize = f.FontSize;
setAx.YDir = f.YDir;
setAx.LineWidth = f.LineWidth;
h(cAx).Box = f.Box;
h(cAx).TickDir = f.TickDir;
h(cAx).TickLength = f.TickLength;
h(cAx).XMinorTick = f.XMinorTick;
h(cAx).YMinorTick = f.YMinorTick;
h(cAx).YGrid = f.YGrid;
h(cAx).XGrid = f.XGrid;
h(cAx).YColor = f.YColor;
h(cAx).XColor = f.XColor;
h(cAx).FontSize = f.FontSize;
h(cAx).YDir = f.YDir;
h(cAx).LineWidth = f.LineWidth;
end
positions(cAx,:) = ax(cAx).Position(:);
% Set labels
if ~obj(1).labels.supx; xlabel(obj(Ax2Obj).labels.xlab); end
if ~obj(1).labels.supy; ylabel(obj(Ax2Obj).labels.ylab); end
%% SHOULD I GO FOR THIS? MAYBE THIS COMPLICATES STUFF
% Make scientific notations on the axes.
h(cAx).YAxis.Exponent = length(num2str(max(abs(round(h(cAx).YLim)))))-1;
h(cAx).XAxis.Exponent = length(num2str(max(abs(round(h(cAx).XLim)))))-1;
end
% Set Label Positions
% TODO: THIS MUST BE DONE WAY BETTER!!
% NOTE THAT AXES ARE NOT SAME SIZE? (SEE MOST RIGHT FIGURES), ALSO
% POSITION IS NOT ALIGNED!
%% Checkout
% Store and update primary obj data
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))];
obj(1).h_ax_plot = ax;
obj(1).h_ax_plot.handles = h;
obj(1).h_ax_plot.sz = graphsz;
end
......
......@@ -7,26 +7,47 @@ function make_legend(obj,varargin)
% PBToolbox (2019): JJH: j.heckman@donders.ru.nl
lgnd = obj(1).h_ax_legend;
if lgnd.bool
h = axes('Units','Normal','Position',[.85 .3 .15 .4],'tag','legend','Visible','off');
hold on;
%% Initialize
% Assert legend and set axis
lgnd = obj(1).h_ax_legend;
if ~lgnd.bool; return; end
ncol = length(unique(obj(1).pva.color));
entries = lgnd.features.entries;
if length(entries) ~= ncol; disp('Error: Number of entries and colors in legend did not match.'); return; end
% Get parameters
col = pb_selectcolor(ncol,obj(1).pva.def);
move = 0;
sz = 0.04;
%% Build Legend
% Set Axis, display entries.
% Set axis
h = axes('Parent',obj(1).parent,'Visible','off','Position',lgnd.pos,'tag','Legend');
xlim([0 1]); ylim([0 1]);
hold on;
% Fill legend entries
for iCol = 1:ncol
pos = 0.5 + (ncol*sz/2) - (iCol-1)*sz -sz/2;
p(iCol) = plot(0,pos,'Marker','o','Visible','on','Color',col(iCol,:),'MarkerFaceColor',col(iCol,:));
t(iCol) = text(0.1,pos,entries{iCol},'Visible','on','FontSize',lgnd.features.fontsize);
ncol = length(unique(obj(1).pva.color));
col = pb_selectcolor(ncol,obj(1).pva.def);
move = 0;
for iCol = 1:ncol
pos = 0.575 - (iCol-1)*.075;
t(iCol) = text(0.1,pos,lgnd.features.entries{iCol},'Visible','on','FontSize',lgnd.features.fontsize);
p(iCol) = plot(0,pos,'Marker','o','Visible','on','Color',col(iCol,:),'MarkerFaceColor',col(iCol,:));
xlim([0 1]);
ylim([0 1]);
if move<t(iCol).Extent(3); move = t(iCol).Extent(3); end
end
move = (.95-move)*0.15;
h.Position(1) = h.Position(1)+move;
% Assert longest entry
if move < t(iCol).Extent(3); move = t(iCol).Extent(3); end
end
% Align right
move = (.95-move) * 0.10;
h.Position(1) = h.Position(1) + move;
%% Checkout
% Store and update primary obj data
obj(1).h_ax_legend.handles = h;
end
......
......@@ -7,18 +7,43 @@ function make_suplabel(obj,varargin)
% 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);
%% Initialize
% Get axes, positions and data
slax = gobjects(0);
% Correct label width for putative legend
legendBoundary = 1;
if obj(1).h_ax_legend.bool
legendBoundary = obj(1).h_ax_legend.handles.Position(1);
end
obj(1).labels.pos = [0 0 legendBoundary 0.975];
% Assess labels
bool = true; if numel(obj) == 1; bool = false; end
lab_x = bool; lab_y = bool;
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;
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
% Set superlabels
obj(1).labels.supx = lab_x;
obj(1).labels.supy = lab_y;
%% Build Suplabel
% Set Axis, display labels.
h = axes('Parent',obj(1).parent,'OuterPosition',obj(1).labels.pos,'Visible','off','tag','Labels');
if lab_x; xlabel(obj(1).labels.xlab,'Visible','on'); end
if lab_y; ylabel(obj(1).labels.ylab,'Visible','on'); end
if ~isempty(obj(1).title); title(obj(1).title,'Visible','on','FontSize',18); end
%% Checkout
% Store and update primary obj data
obj(1).h_ax_labels = h;
obj(1).h_ax_plot.playground = h.Position;
end
......
......@@ -8,18 +8,18 @@ function set_grid(obj,varargin)
% PBToolbox (2019): JJH: j.heckman@donders.ru.nl
v = varargin;
f.Box = pb_keyval('box',v,'off');
f.TickDir = pb_keyval('tickdir',v,'in');
f.TickLength = pb_keyval('ticklength',v,[.02 .02]);
f.Box = pb_keyval('Box',v,'off');
f.TickDir = pb_keyval('Tickdir',v,'in');
f.TickLength = pb_keyval('Ticklength',v,[.02 .02]);
f.XMinorTick = pb_keyval('XMinorTick',v,'on');
f.YMinorTick = pb_keyval('YMinorTick',v,'on');
f.YGrid = pb_keyval('YGrid',v,'on');
f.XGrid = pb_keyval('XGrid',v,'on');
f.YColor = pb_keyval('YColor',v,[.3 .3 .3]);
f.XColor = pb_keyval('XColor',v,[.3 .3 .3]);
f.FontSize = 10;
f.YDir = 'normal';
f.LineWidth = .1;
f.FontSize = pb_keyval('FontSize',v,10);
f.YDir = pb_keyval('YDir',v,'normal');
f.LineWidth = pb_keyval('LineWidth',v,0.1);
obj(1).grid.bool = true;
obj(1).grid.features = f;
......
......@@ -14,8 +14,9 @@ function set_legend(obj,varargin)
f.fontname = pb_keyval('Fontname',v,'Helvetica');
obj(1).h_ax_legend.bool = true;
obj(1).h_ax_legend.handles = {};
obj(1).h_ax_legend.handles = [];
obj(1).h_ax_legend.features = f;
obj(1).h_ax_legend.pos = [.85 .1 .15 .8];
end
......
......@@ -36,7 +36,7 @@ run = 1; % Set # of blocks to run
% Make figure 2: Plot rawdata + bubbleplot
if run>cfn
tic
%tic
% Make figure
cfn = pb_newfig(cfn,'size',[0 0 17 11],'resize','off');
for iR = 1:2
......@@ -64,8 +64,8 @@ if run>cfn
% Build
d.draft;
d.print('disp',true);
toc
%d.print('disp',true);
%toc
end
%% Block 3:
......
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