function resizableSplitPanel
f = figure('Name', 'Resizable Split Panel', ...
'Units', 'Normalized', ...
'Position', [0.2, 0.2, 0.6, 0.6]);
panelLeft = uipanel('Parent', f, ...
'Units', 'Normalized', ...
'Position', [0, 0, 0.5, 1], ...
panelRight = uipanel('Parent', f, ...
'Units', 'Normalized', ...
'Position', [0.5, 0, 0.5, 1], ...
ax1 = axes('Parent', panelLeft);
ax2 = axes('Parent', panelRight);
splitter = uipanel('Parent', f, ...
'Units', 'Normalized', ...
'Position', [0.495, 0, 0.01, 1], ...
'BackgroundColor', 'k', ...
'ButtonDownFcn', @startDragFcn);
function startDragFcn(~, ~)
startPoint = get(f, 'CurrentPoint');
set(f, 'WindowButtonMotionFcn', @draggingFcn);
set(f, 'WindowButtonUpFcn', @stopDragFcn);
function draggingFcn(~, ~)
currentPoint = get(f, 'CurrentPoint');
dx = currentPoint(1) - startPoint(1);
startPoint = currentPoint;
posLeft = get(panelLeft, 'Position');
posRight = get(panelRight, 'Position');
posSplitter = get(splitter, 'Position');
newWidthLeft = posLeft(3) + dx;
newWidthRight = posRight(3) - dx;
if newWidthLeft > 0.1 && newWidthRight > 0.1
set(panelLeft, 'Position', [posLeft(1), posLeft(2), newWidthLeft, posLeft(4)]);
set(panelRight, 'Position', [posRight(1) + dx, posRight(2), newWidthRight, posRight(4)]);
set(splitter, 'Position', [posSplitter(1) + dx, posSplitter(2), posSplitter(3), posSplitter(4)]);
function stopDragFcn(~, ~)
set(f, 'WindowButtonMotionFcn', '');
set(f, 'WindowButtonUpFcn', '');