th1 = linspace(0,pi*11/6,12);
r1 = cos(th1);
th2 = linspace(5*pi/6,9*pi/6,20);
r2 = linspace(1,.1,20);
fig = uifigure();
ax = polaraxes(fig);
hold(ax,'on')
polarplot(ax, th1, r1, 'b-','LineWidth',2);
polarplot(ax, th2, r2, 'ro','MarkerFaceColor', 'r');
polarplot(ax, 0, .9, 'kp', 'MarkerSize', 16, 'MarkerFaceColor', 'y')
titleHandle = title(ax,'Orientation: 0 deg');
ax.Position([2,4]) = ax.Position([2,4])+[.15,-.15];
uilabel(fig, 'position', [20 60, 400,20], 'Text', 'Adjust orientation of polar axes (deg from ThetaZeroLocation)');
sldr = uislider(fig, 'Position', [20, 50, 520, 3], 'Value', 0, 'Limits', [-180,180],...
'MajorTicks', -180:30:180, 'MinorTicks', [], 'UserData', 0, ...
'ValueChangingFcn', @(sldr,event)updatePolarTicks(sldr,event,ax,titleHandle));
drawnow(); pause(0.05)
function updatePolarTicks(sldr,event,ax,titleHandle)
titleHandle.String = sprintf('Orientation: %.0f deg', event.Value);
rotation = event.Value - sldr.UserData;
sldr.UserData = event.Value;
dwrap = @(d)mod(d,360) + (d>0 & mod(d,360)==0).*360;
deg = dwrap(rotation);
rad = pi/180*deg;
chil = ax.Children;
thData = get(chil, 'ThetaData');
thDataRot = cellfun(@(c){c+rad},thData);
set(chil, {'ThetaData'}, thDataRot)
origTickLabs = ax.ThetaTickLabel;
[newTicks, tickLabIdx] = unique(dwrap(unique(mod(ax.ThetaTick,360),'stable') + deg));
ax.ThetaTick = newTicks;
ax.ThetaTickLabel = origTickLabs(tickLabIdx);
end
Best Answer