如何在MATLAB中绘制第二个图形而不是颜色编码 [英] How to plot a second graph instead of color coding in matlab

查看:166
本文介绍了如何在MATLAB中绘制第二个图形而不是颜色编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



事情是,我在曲面上有一个轨迹一个行星/月球的任何东西(一个.mat随时间和坐标),然后我有一些.mat随着时间和当时的测量。



我是能够在散点图()中将其绘制为颜色编码轨迹(使用测量和坐标),这非常棒。然而,我的问题是我需要一些东西更复杂
我现在需要采取轨迹,而不是颜色编码它,我应该添加测量(这是给每个点)的图形(价值)的轨迹(这不总是一条直线),我会添加一个小图来解释我想要的,红色箭头显示我想要添加到我的情节,绿色显示我有什么。



$ / $> $ / $> $ / $> $ / $> $ / $> b
$ b

  x = 0:0.1:10; 
y = x;
m = 10 * sin(x);

因此,您需要的是每个数据点处的曲线法向量:

  dx = diff(x); %2向后有限差分:终点
dx = [dx(1)dx]; %第1点的正向有限差分
dy = diff(y);
dy = [dy(1)dy];
curve_tang = [dx; DY];
%逆时针旋转切向90°
curve_norm = [--dy; DX];
%对矢量进行归一化:
nrm_cn = sqrt(sum(abs(curve_norm)。^ 2,1));
curve_norm = curve_norm ./ repmat(sqrt(sum(abs(curve_norm)。^ 2,1)),2,1);

将该向量与测量值相乘( m ),用数据点坐标抵消它,你就完成了:

  mx = x + curve_norm(1,:)。*米; 
my = y + curve_norm(2,:)。* m;

将其与以下图表合并:

 图。坚持
轴相等;
scatter(x,y,[],m);
plot(mx,my)



这正是您想要的。这个例子只有一条直线作为坐标,但是这段代码可以处理任何曲线:

  x = 0:0.1: 10; Y = X ^ 2; M =的sin(x); 

$ b

  t = 0:pi / 50:2 * pi; x = 5 * cos(t) ; Y = 5 * SIN(T); M = SIN(5 * T); 


i just started with my master thesis and i already am in trouble with my capability/understanding of matlab.

The thing is, i have a trajectory on a surface of a planet/moon whatever (a .mat with the time, and the coordinates. Then i have some .mat with time and the measurement at that time.

I am able to plot this as a color coded trajectory (using the measurement and the coordinates) in scatter(). This works awesomely nice.

However my problem is that i need something more sophisticated. I now need to take the trajectory and instead of color-coding it, i am supposed to add the graph (value) of the measurement (which is given for each point) to the trajectory (which is not always a straight line). I will added a little sketch to explain what i want. The red arrow shows what i want to add to my plot and the green shows what i have.

解决方案

You can always transform your data yourself: (using the same notation as @Shai)

x = 0:0.1:10;
y = x;
m = 10*sin(x);

So what you need is the vector normal to the curve at each datapoint:

dx = diff(x); % backward finite differences for 2:end points
dx = [dx(1) dx]; % forward finite difference for 1th point
dy = diff(y);
dy = [dy(1) dy];
curve_tang = [dx ; dy];
% rotate tangential vectors 90° counterclockwise
curve_norm = [-dy; dx];
% normalize the vectors:
nrm_cn = sqrt(sum(abs(curve_norm).^2,1));
curve_norm = curve_norm ./ repmat(sqrt(sum(abs(curve_norm).^2,1)),2,1);

Multiply that vector with the measurement (m), offset it with the datapoint coordinates and you're done:

mx = x + curve_norm(1,:).*m;
my = y + curve_norm(2,:).*m;

plot it with:

figure; hold on
axis equal;
scatter(x,y,[],m);
plot(mx,my)

which is imo exactly what you want. This example has just a straight line as coordinates, but this code can handle any curve just fine:

x=0:0.1:10;y=x.^2;m=sin(x);

t=0:pi/50:2*pi;x=5*cos(t);y=5*sin(t);m=sin(5*t);

这篇关于如何在MATLAB中绘制第二个图形而不是颜色编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆