gpt4 book ai didi

linux - 在 MATLAB 和 Octave 中更改罗盘轴

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:19:17 26 4
gpt4 key购买 nike

我正在使用 octave 3.8.1 Linux 的 compass 绘图函数绘制圆形数据集,但我很难更改此绘图的轴。

具体来说,我想删除一些轴点(例如 30 度和 60 度),而且我想更改数字(例如将 90 写成 30)。

有没有人知道如何做到这一点?


代码示例:连同它生成的图像

%compass plot
clear all,clc
x_angle=[45,90,123,43,53,23,53,12];
y_amp=[1,.5,.4,.1,.6,.3,.7,.3];
[x_cart,y_cart]=pol2cart([x_angle-180]*pi/180,y_amp);
h = compass(x_cart,y_cart);

for k = 1:length(x_cart)
a_x = get(h(k), 'xdata');
b_y = get(h(k), 'ydata');
%//To delete the arrows you need to delete all but the first two entries
%//in the xdata and ydata fields of the plot. The color can be changed
%//by setting the color property. Please find below a solution for
%//compass plots with arbitrary numbers of arrows.
set(h(k), 'xdata', a_x(1:2), 'ydata', b_y(1:2), 'color', 'r')
end;

Compass Plot

最佳答案

这是一个 hack,因为 compass 图与我习惯的有点不同,但我们可以这样做:

删除标签

您可以使用 findall 命令使用当前焦点图形(这是您的罗盘图),并将所有不需要的字符串替换为空白字符串。换句话说,如果您想删除图中所有具有 3060 的实例,您可以这样做:

set(findall(gcf, 'String', '30', '-or', 'String', '60') ,'String', '  ');

这意味着您要设置数字,以便我们找到任何包含 3060 的字符串,并将它们替换为空白字符串。注意空白字符串中有两个空格作为set的最后一个参数。使用单个空格不起作用。如果你只想一次做一个标签,你可以这样做:

set(findall(gcf, 'String', '30'), 'String', '  ');
set(findall(gcf, 'String', '60'), 'String', ' ');

修改标签

我们仍然可以使用上面相同的语法。但是,不要执行空白字符串,而是将其替换为您选择的字符串。对于您的示例,您希望将标签从 90 更改为 30。因此:

set(findall(gcf, 'String', '90'), 'String', '30');

需要注意的一件好事是数字是字符串。将它们设置为实际数字不会有任何作用。


希望对您有所帮助!顺便说一句,在制作可重现的例子方面做得很好。它让我可以轻松地进行测试。

关于linux - 在 MATLAB 和 Octave 中更改罗盘轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24938458/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com