在Matlab中的2种不同类型的曲线之间插值曲线 [英] plot interpolate a curve between 2 different types of curves in matlab

查看:470
本文介绍了在Matlab中的2种不同类型的曲线之间插值曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下数据在两条曲线的中间预测一条曲线,这些方程具有不同的方程和数据,我还需要对中间曲线的曲线进行样条化和加深处理 我曾尝试在stackoverflow中搜索其他代码,但这是最接近正确解决方案的方法.到目前为止,两条曲线的图是正确的,但是插值点给了我错误的图.

I have the following data that predicts a curve in the middle of the two curves which has different equation and datas.I also need to spline and smothen the curve of the middle curve I've tried searching other codes here in stackoverflow but this is the most close to the right solution. So far the plot for the two curve is right but the interpolated point gives me wrong plot.

鉴于(a25,vel25)= 25和(a50,vel50)= 50,我试图找到val = 30的图.请帮助我进行故障排除并获取生成的内插曲线的数据表(x,y).谢谢你的帮助 使用此程序生成的图

Im trying to find the plot for val=30 given that (a25,vel25)=25 and (a50,vel50)=50. Please help me troubleshoot and get a table of data (x,y) for the generated interpolated curve. Thanks for your help generated plot using this program

a50=[1.05
0.931818182
0.931818182
0.968181818
1.045454545
1.136363636
1.354545455
1.568181818
1.718181818
1.945454545
2.159090909
2.454545455
2.772727273
];
vel50=[0.85
0.705555556
0.605555556
0.533333333
0.472222222
0.45
0.427777778
0.45
0.477777778
0.533333333
0.611111111
0.711111111
0.827777778
];
a25=[0.5
0.613636364
0.686363636
0.795454545
0.918181818
0.963636364
1.090909091
1.236363636
1.304545455
1.431818182
1.545454545
1.659090909
1.818181818
];
vel25=[0.425555556
0.354444444
0.302222222
0.266666667
0.233333333
0.226666667
0.211111111
0.222222222
0.237777778
0.266666667
0.311111111
0.35
0.402222222
];
plot(a25,vel25,'b-');
hold on
plot(a50,vel50,'g-');
minX = min([a25 a50]);
maxX = max([a25,a50]);
xx = linspace(minX,maxX,100);
vel25_inter = interp1(a25,vel25,xx);
vel50_inter = interp1(a50,vel50,xx);
val = 30; % The interpolated point
interpVel = vel25_inter + ((val-25).*(vel50_inter-vel25_inter))./(50-25);
plot(xx,interpVel,'r-');

推荐答案

评论中链接的问题和答案仍然适用,可以作为解决方案.

The question and answer linked in comment still apply and can be a solution.

在您的情况下,它不是那么直接,因为您的数据不在同一网格中,并且某些数据不是单调的,但是一旦正确打包,最简单的解决方案仍然是使用griddata.

In your case, it is not so direct because your data are not on the same grid and some are not monotonic, but once they are packaged properly, the easiest solution is still to use griddata.

通过正确包装,我的意思是找到最大的公共间隔(在x上或在您称为a上),以便可以在曲线之间插值数据而不会产生NaN s.

By packaged properly, I mean finding the maximum common interval (on x, or what you call a), so the data can be interpolated between curve without producing NaNs.

这似乎有效: 红色虚线是在val=30处插值的值,其他所有线都是在25到50之间的值的插值.

This seems to work: The red dashed line is the values interpolated at val=30, all the other lines are interpolations for values between 25 to 50.

到达那里的代码:

% back up original data, just for final plot
bkp_a50 = a50 ; bkp_vel50 = vel50 ;

% make second x vector monotonic
istart = find( diff(a50)>0 , 1 , 'first') ;
a50(1:istart-1) = [] ;
vel50(1:istart-1) = [] ;

% prepare a 3rd dimension vector (from 25 to 50)
T = [repmat(25,size(a25)) ; repmat(50,size(a50)) ] ;
% merge all observations together
A = [  a25 ;   a50] ;
V = [vel25 ; vel50] ;

% find the minimum domain on which data can be interpolated
% (anything outside of that will return NaN)
Astart = max( [min(a25) min(a50)] ) ;
Astop  = min( [max(a25) max(a50)] ) ;

% use the function 'griddata'
[TI,AI] = meshgrid( 25:50 , linspace(Astart,Astop,10)  ) ; 
VI = griddata(T,A,V,TI,AI) ;

% plot all the intermediate curves
plot(AI,VI)
hold on
% the original curves
plot(a25,vel25,'--k','linewidth',2)
plot(bkp_a50,bkp_vel50,'--k','linewidth',2)
% Highlight the curve at T = 30 ;
c30 = find( TI(1,:) == 30 ) ;
plot(AI(:,c30),VI(:,c30),'--r','linewidth',2)

这篇关于在Matlab中的2种不同类型的曲线之间插值曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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