【问题标题】:Colored MATLAB Compass Graph彩色 MATLAB 罗盘图
【发布时间】:2011-11-01 06:58:09
【问题描述】:

我对 MATLAB 很陌生,因此非常感谢任何帮助。

我想使用 MATLAB 的 compass 图表来可视化多个向量。是否可以为不同的向量着色?这些向量会随着时间而变化,并且它们被传递到罗盘图的顺序永远不会改变。有没有其他区分向量的方法?

提前感谢您! M.

编辑:该解决方案有效(即箭头是彩色的),直到到达指南针的最后一个矢量元素。如果我之前没有停止循环,该方法将退出并出现错误??? Subscript indices must either be real positive integers or logicals.. 指南针的每个对象(即箭头)都正确寻址,除了最后一个;检查了索引,似乎一切正常。我该怎么办?

这是我目前使用的代码:

handle = compass(viewframe(1,:),viewframe(2,:));
colors = get(0,'DefaultAxesColorOrder');
for i=1:length(handle)
   set(handle(i),'color', colors(mod(i,length(colors)),:))
end

【问题讨论】:

    标签: matlab graph plot compass-geolocation


    【解决方案1】:

    @cyborg 答案的基础上,您可以在一次调用中分配颜色:

    Z = eig(randn(5));
    clr = lines(numel(Z));  %# colors you want to use
    
    h = compass(Z);         %# compass(real(Z),imag(Z))
    set(h, {'Color'},num2cell(clr,2), 'LineWidth',2)
    

    您也可以使用图例进行注释:

    str = cellstr( num2str((1:numel(Z))','Arrow %d') );  %'
    legend(h, str, 'Location','BestOutside')
    

    【讨论】:

    • @Marcus:啊,你使用MOD函数的方式有点不对劲:当循环变量i等于length(colors)的倍数时,余数是0因此无效的下标错误...我修复了 cyborg 的答案
    • 谢谢@Amro,我总是忘记 Matlab 索引是从 1 开始的。
    【解决方案2】:

    你可以这样做:

    Z = compass(eig(randn(5)));
    colors = get(0,'DefaultAxesColorOrder')
    for i=1:length(Z)
        set(Z(i),'color',colors(mod(i-1,length(colors))+1,:))
    end    
    

    【讨论】:

      猜你喜欢
      • 2017-12-22
      • 2015-06-14
      • 1970-01-01
      • 1970-01-01
      • 2014-12-31
      • 2012-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多