彩色 MATLAB 罗盘图

发布于 2024-12-11 21:19:56 字数 645 浏览 2 评论 0原文

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

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

先感谢您! M.

编辑:该解决方案有效(即箭头是彩色的),直到到达罗盘的最后一个向量元素。如果我之前没有停止循环,该方法将退出并出现错误??? 下标索引必须是实数正整数或逻辑数。 罗盘的每个对象(即箭头)都被正确定位,除了最后一个;检查了索引,一切似乎都正常。我能做什么?

这是我当前使用的代码:

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

I'm quite new to MATLAB and therefore any help is very appreciated.

I want to visualize multiple vectors using MATLAB's compass graph. Is it possible to colorize the different vectors? Those vectors change over time and the order in which they're handed to the compass graph never changes. Is there another way to distinguish the vectors?

Thank you in advance!
M.

EDIT: The solution works (i.e. arrows are colored) until the very last vector element of the compass is reached. If I do not stop the loop before, the method exits with the error ??? Subscript indices must either be real positive integers or logicals.. Every object (i.e. arrows) of the compass is correctly adressed except the last; checked the indexes, everything seems to be ok.What can I do?

Here's the code I currently use:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月蹉跎了容颜 2024-12-18 21:19:56

基于 @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)

< img src="https://i.sstatic.net/KwLs2.png" alt="compass">

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

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

Building on @cyborg answer, you could assign the colors in one call:

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)

compass

You could also use a legend for annotation:

str = cellstr( num2str((1:numel(Z))','Arrow %d') );  %'
legend(h, str, 'Location','BestOutside')
小鸟爱天空丶 2024-12-18 21:19:56

你可以这样做:

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    

You could do this:

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    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文