如何在MATLAB中使用一组点来绘制曲线 [英] How to plot a curved line in MATLAB using a set of points

查看:1800
本文介绍了如何在MATLAB中使用一组点来绘制曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用以下命令使用现有的一组值来绘制 ROC曲线

 积(X1,Y1, ' -  RS',X2,Y2, ' -  * G'); 

其中 X1 Y1 X2 Y2 是具有相同大小的矩阵



然而,这个命令产生的直线是直线的。



我怎样才能让它们成为曲线。



Thanks
Aziz

解决方案

MATLAB默认使用直线逼近在控制点之间绘制图表。如果需要,可以在点之间插入以生成更真实的图形。尝试使用 interp1 'spline'选项,看看结果如何。因此,找出 X1 X2 的最小值和最大值,然后定义一个点之间的网格粒度更细的最小值和最大值。一旦你这样做,把它扔进 interp1 并绘制你的曲线。例如:

 %//找到Xs 
minX1 = min(X1)的域的动态范围;
maxX1 = max(X1);
minX2 = min(X2);
maxX2 = max(X2);

%//生成Xs
x1Vals = linspace(minX1,maxX1,100);
x2Vals = linspace(minX2,maxX2,100);

%//内插曲线
y1Vals = interp1(X1,Y1,x1Vals,'spline');
y2Vals = interp1(X2,Y2,x2Vals,'spline');

%//绘制结果
plot(x1Vals,y1Vals,' - rs',x2Vals,y2Vals,' - * g');

linspace 生成一个点从一端到另一端的网格,并且我指定了100个点。然后,我们按照指定控制点( X1,Y1,X2,Y2 )的方式使用 interp1 ,然后指定我想插入的值。我使用插值后的输出值并绘制曲线。

I'm trying to draw ROC curves using an existing set of values using the following command

plot(X1,Y1,'--rs',X2,Y2,'-*g');

Where X1,Y1,X2 and Y2 are matrices that have the same size

However, the lines produced by this command are straight ones.

How can I make them curved lines.

Thanks Aziz

解决方案

MATLAB by default uses straight line approximation to draw your graph in between control points. If you want, you can interpolate in between the points to produce a more realistic graph. Try using interp1 with the 'spline' option and see how that goes. As such, figure out the minimum and maximum values of both X1 and X2, then define a grid of points in between the minimum and maximum that have finer granularity. Once you do this, throw this into interp1 and plot your curve. Something like:

%// Find dynamic range of domain for both Xs
minX1 = min(X1);
maxX1 = max(X1);
minX2 = min(X2);
maxX2 = max(X2);

%// Generate grid of points for both Xs
x1Vals = linspace(minX1, maxX1, 100);
x2Vals = linspace(minX2, maxX2, 100);

%// Interpolate the curves
y1Vals = interp1(X1, Y1, x1Vals, 'spline');
y2Vals = interp1(X2, Y2, x2Vals, 'spline');

%// Plot the results
plot(x1Vals,y1Vals,'--rs',x2Vals,y2Vals,'-*g');

linspace generates a grid of points from one end to another, and I specified 100 of these points. I then use interp1 in the way we talked about where you specify control points (X1,Y1,X2,Y2), then specify the values I want to interpolate with. I use the output values after interpolation and draw the curve.

这篇关于如何在MATLAB中使用一组点来绘制曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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