Theta marked in radians for ezpolar?

조회 수: 10 (최근 30일)
Gary Raduns
Gary Raduns 2020년 8월 24일
댓글: Adam Danz 2020년 8월 24일
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???

채택된 답변

Adam Danz
Adam Danz 2020년 8월 24일
편집: Adam Danz 2020년 8월 24일
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
  댓글 수: 2
Gary Raduns
Gary Raduns 2020년 8월 24일
Thank you. It looks like the better resolution to introduce this in Matlab is to create the table of values, use polarplot, and convert thee axes to radians.
Adam Danz
Adam Danz 2020년 8월 24일
polarplot is definitely a better option than polar() or expolar().

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Polar Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by