MATLAB: Theta marked in radians for ezpolar

ezpolarfractionspipolarradiansticks

I have read and successfully converted the default degree measure to radians for a polarplot. The same procedure does not appear to work with ezpolar. How do you get theta marked in radians for ezplot?
This code has the desired effect:
theta=linspace(0, 2*pi, 100);
rho=1+3/2*sin(2*theta);
polarplot(theta, rho)
ax=gca;
ax.ThetaAxisUnits='radians';
This code leaves the theta markings in degrees
ezpolar(@(t) 1+3/2*sin(2*t), [0, 2*pi])
ax=gca;
ax.ThetaAxisUnits='radians'
Prefacing the latter with polaraxes() gets both units.
Why, why, why is the expected input for both polarplot and ezpolar in radians (seems sensible as a calculus instructor), but the default theta marking in degrees???

Best Answer

polarplot uses polaraxes whereas expolar creates a pseudo-polar-plot on regular Cartesian axes. The ThetaAxisUnits property is not available with Cartesian axes. Instead, the theta ticks are added as text objects.
I recommend using polaraxes unless you have a very good reason not to.
To convert the theta ticks in the expolar plot to radians, you'll have to identify which text objects are the theta ticks and then convert them to radians.
This demo uses fractions to label the theta ticks.
ezpolar(@(t) 1+3/2*sin(2*t), [0, 2*pi])
ax=gca;
% Get all text objects
h = findall(ax, 'type', 'text');
% Loop through each text object. If it appears to be a
% theta tick label, convert it to radians.
existingTicks = 0:30:360; % List existing theta ticks
existingTickStr = strsplit(num2str(existingTicks));
for i = 1:numel(h)
if ismember(h(i).String, existingTickStr)
[num,denom] = rat(str2double(h(i).String)/180);
if num==0 || denom==1
h(i).String = sprintf('%d\\pi', num/denom);
else
h(i).String = sprintf('^{%d}/_{%d} \\pi', num, denom);
end
end
end
For more simpler decimal labels, replace the inside of the loop with,
if ismember(h(i).String, existingTickStr)
h(i).String = sprintf('%.2f',str2double(h(i).String)*pi/180);
end
Related Question