声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1229|回复: 3

【求助】想实现非线性数据的插值

[复制链接]
发表于 2006-7-7 15:19 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
x=[1 2 3 4 5]
y=[10 20 30 20 10 ]
假如想得到在y=25处的两个x值,应该怎么做
interp1是只能实现线性插值,高手指点
回复
分享到:

使用道具 举报

 楼主| 发表于 2006-7-7 16:12 | 显示全部楼层
找到一个解决办法
table=[a; b].'
xi=mminterp(table, 2, 25)

函数定义如下
function y=mminterp(tab, col, val)
%MMINTERP 1-D Table Search by Linear Interpolation.

%Y=MMINTERP(TAB,COL,VAL) linearly interpolates the table

%TAB searching for the scalar value VAL in the column COL.

%All crossings are found and TAB(:,COL) need not be monotonic.

%Each crossing is returned as a separate row in Y and Y has as

%many columns as TAB.Naturally,the column COL of Y contains

%the value VAL. If VAL is not found in the table,Y=.

%Copyright (c) 1996 by Prentice-Hall,Inc.

[rt, ct]=size(tab);

if length(val) > 1,error(' VAL must be a scalar. '),end

if col>ct|col < 1,error(' Chosen column outside table width. '),end

if rt < 2,error(' Table too small or not oriented in columns. '),end

above=tab(: , col) > val;%True where > VAL

below=tab(: , col) < val;%True where < VAL

equal=tab(: , col) == val;%True where = VAL

if all(above == 0) | all(below == 0),%handle simplest case

y=tab(find(equal), : );return

end

pslope=find(below(1:rt-1)&above(2:rt));%indices where slope is +

nslope=find(below(2:rt)&above(1:rt-1));%indices where slope is -

ib=sort([pslope; nslope+1]);%put indices below in order

ia=sort([nslope; pslope+1]);%put indices above in order

ie=find(equal);%indices where equal to val

[tmp,ix]=sort( [ib, ie] );%find where equals fit in result

ieq=ix > length(ib);%True where equals values fit

ry=length(tmp);%# of rows in result y

y=zeros(ry, ct);%poke data into a zero matrix

alpha=(val-tab(ib,col))./(tab(ia,col)-tab(ib,col));

alpha=alpha(: , ones(1, ct));%duplicate for all columns

y(~ieq, : )=alpha.*tab(ia, : )+(1-alpha).*tab(ib, : );%interpolated values

y(ieq, : )=tab(ie, : );%equal values

y( : , col)=val*ones(ry, 1);%remove roundoff error
发表于 2006-7-8 11:36 | 显示全部楼层
强,试一下。
发表于 2006-7-10 02:18 | 显示全部楼层
有这么复杂吗?
  1. xx=linspace(1,5,150);
  2. yy=spline(x,y,xx);
  3. f=xx(yy>=24.9&yy<=25.001)
复制代码

result return:

  1. f =
  2.     2.3423    3.6577
复制代码
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-20 04:51 , Processed in 0.059541 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表