根据函数MATLAB给出的色图填充两条曲线之间的距离 [英] Filling between two curves, according to a colormap given by a function MATLAB
本文介绍了根据函数MATLAB给出的色图填充两条曲线之间的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何用适合函数值的颜色图填充两条曲线之间的区域.
How can the area between two curves be filled by a colormap that fits the values of a function.
例如,这是两条曲线,以及我希望介于两者之间的值的函数
for example, here are the two curves, and the function of the values I would like to have in between
L=5;
x=1:10;
t=(1:10)/10;
figure(1)
subplot(2,1,1)
plot(x,t,x+L,t)
subplot(2,1,2)
plot(x,exp(-(x/L).^2))
填充区域应从任何颜色图中获取.
The filled area should be taken from any colormap.
推荐答案
通过一些基本的索引编制,高斯长度和线方程数学的重新换算,我们可以通过以下方式实现:
With some basic indexing, rescaling of the gaussian length and line equation maths, we can do this by:
L=5;
x=1:10;
t=(1:10)/10;
[X,Y]=meshgrid(linspace(0,x(end)+L,500),linspace(0,t(end),500));
%slope of both lines
m=(t(2)-t(1))/(x(2)-x(1));
for ii=1:size(X,1)
z(ii,:)=exp(-((X(ii,:)-Y(ii,1)/m)/(L/2)).^2);
end
% basic line maths an dindexing
z(Y./X>m)=NaN;
z((Y+m*L)./X<m)=NaN;
surf(X,Y,z,'linestyle','none')
view(2)
这篇关于根据函数MATLAB给出的色图填充两条曲线之间的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文