2

因此,matlab 正确地将弧度用于三角函数和极坐标图的实际绘图。然而令人讨厌的是,它将角轴以度为单位,有什么办法可以改变它吗?

4

1 回答 1

4

表示角度值的文本对象由polar函数在其代码的以下部分(Matlab R2010b)中创建:

% annotate spokes in degrees
rt = 1.1 * rmax;
for i = 1 : length(th)
    text(rt * cst(i), rt * snt(i), int2str(i * 30),...
        'HorizontalAlignment', 'center', ...
        'HandleVisibility', 'off', 'Parent', cax);
    if i == length(th)
        loc = int2str(0);
    else
        loc = int2str(180 + i * 30);
    end
    text(-rt * cst(i), -rt * snt(i), loc, 'HorizontalAlignment', 'center', ...
        'HandleVisibility', 'off', 'Parent', cax);
end

由于由代码'HandleVisibility'设置为'off',这些文本对象在函数外部不可见,因此您无法修改它们的'String'属性。

您可以创建一个修改版本polar(在用户文件夹中以不同的名称保存),其中上述部分替换为:

% annotate spokes in degrees
rt = 1.13 * rmax;
text_strings = {'\pi/6'  '\pi/3'  '\pi/2'  '2\pi/3' '5\pi/6'  '\pi' ...
                '7\pi/6' '4\pi/3' '3\pi/2' '5\pi/3' '11\pi/6' '0'};
for i = 1 : length(th)
    text(rt * cst(i), rt * snt(i), text_strings{i}, ...
        'HorizontalAlignment', 'center', ...
        'HandleVisibility', 'off', 'Parent', cax);
    text(-rt * cst(i), -rt * snt(i), text_strings{i+6}, ...
        'HorizontalAlignment', 'center', ...
        'HandleVisibility', 'off', 'Parent', cax);
end

对此代码的评论:

  • 也许您更喜欢在text_strings不简化分数的情况下进行定义(即'2\pi/6',而不是'\pi/3'等)。
  • 第一1.13行中的 (最初1.1是 )经过微调以匹配字符串的长度。您可能需要更改该值是您使用不同的字符串

这是一个示例结果(我调用了修改后的函数polar_rad.m):

theta = 0:.01:2*pi;
rho = sin(theta).^2;
polar_rad(theta, rho)

在此处输入图像描述

于 2015-03-04T11:52:30.220 回答