首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >matlab中的着色箭矢量

matlab中的着色箭矢量
EN

Stack Overflow用户
提问于 2017-02-26 07:18:34
回答 1查看 471关注 0票数 0

我有四个向量,前三个是复数,第四个是它们的求和。

我成功地用箭笔画出了它们,但是,我需要把第四幅画成红色。我怎么才能把第四张染成红色呢?

代码语言:javascript
运行
复制
% vectors I want to plot as rows (XSTART, YSTART) (XDIR, YDIR)
rays = [
  0 0   real(X1) imag(X1) ;
  0 0   real(X2) imag(X2) ;
  0 0   real(X3) imag(X3) ;
  0 0   real(SUM) imag(SUM) ;
] ;

% quiver plot
quiver(rays( :,1 ), rays( :,2 ), rays( :,3 ), rays( :,4 ));

% set interval
axis([-30 30 -30 30]);

或者我应该使用plotv?https://www.mathworks.com/help/nnet/ref/plotv.html

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-26 10:51:21

handle函数返回的quiver函数不允许访问每个单个元素以更改其属性,在本例中是颜色。

一个可能的工作,虽然不完全优雅,但可以是:

  • 绘制整组数据的抖动图
  • 从轴上移除要更改颜色的元素的uvxy数据。
  • 设置hold on
  • 再次绘制整个数据集的quiver
  • 从轴上移除不想更改颜色的元素的uvxy数据。
  • 将所需的颜色设置为剩余的项目

建议的办法的一个可能的执行可以是:

代码语言:javascript
运行
复制
% Generate some data
rays = [
  0 0   rand-0.5 rand-0.5 ;
   0 0  rand-0.5 rand-0.5 ;
   0 0  rand-0.5 rand-0.5 ;
] ;
rays(4,:)=sum(rays)

% Plot the quiver for the whole matrix (to be used to check the results
figure
h_orig=quiver(rays( :,1 ), rays( :,2 ), rays( :,3 ), rays( :,4 ));
grid minor
% Plot the quiver for the whole matrix
figure
% Plot the quiver for the whole set of data
h0=quiver(rays( :,1 ), rays( :,2 ), rays( :,3 ), rays( :,4 ));
% Get the u, v, x, y data
u=get(h0,'udata')
v=get(h0,'vdata')
x=get(h0,'xdata')
y=get(h0,'ydata')
% Delete the data of the last element
set(h0,'udata',u(1:end-1),'vdata',v(1:end-1),'xdata', ...
   x(1:end-1),'ydata',y(1:end-1))
% Set hold on
hold on
% Plot again the quiver for the whole set of data
h0=quiver(rays( :,1 ), rays( :,2 ), rays( :,3 ), rays( :,4 ));
% Delete the u, v, x, y data of the element you do not want to change the
% colour
set(h0,'udata',u(end),'vdata',v(end),'xdata', ...
   x(end),'ydata',y(end))
% Set the desired colour to the remaining object
h0.Color='r'
grid minor

希望这能帮上忙

卡普拉

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42465800

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档