- 在线时间
- 36 小时
- 最后登录
- 2017-7-6
- 注册时间
- 2009-4-19
- 听众数
- 5
- 收听数
- 1
- 能力
- 0 分
- 体力
- 2412 点
- 威望
- 98 点
- 阅读权限
- 60
- 积分
- 1865
- 相册
- 0
- 日志
- 1
- 记录
- 1
- 帖子
- 316
- 主题
- 28
- 精华
- 0
- 分享
- 0
- 好友
- 24
TA的每日心情 | 开心 2014-9-21 08:29 |
|---|
签到天数: 19 天 [LV.4]偶尔看看III
- 自我介绍
- 我思我在
群组: 数学建模 群组: 中国矿业大学数学建模协会 群组: 数学趣味、游戏、IQ等 群组: 南京邮电大学数模协会 群组: LINGO |
function y=mminterp(tab,col,val)
. U5 p: N. O3 D2 R# @%MMINTERP 1-D Table Search by Linear Interpolation.
1 r/ L4 }6 X1 Z6 K) h3 t3 J% Y=MMINTERP(TAB,COL,VAL) linearly interpolates the table, j, O5 K; m7 [% Y2 R
% TAB searching for the scalar value VAL in the column COL." H j* X: f" Q' o7 s
% All crossings are found and TAB(:,COL) need not be monotonic.
! r$ a, v" ?: _2 u9 m1 p8 T% Each crossing is returned as a separate row in Y and Y has as
& z+ B' b0 t/ o9 ]$ Y7 m3 @% s) K% many columns as TAB. Naturally, the column COL of Y contains" v+ T9 }% N. u3 W9 X$ U# l
% the value VAL. If VAL is not found in the table, Y=[].3 q' g( o& q* u( k. }2 U+ V
7 ^# i3 e' G; {' O5 g. h% D.C. Hanselman, University of Maine, Orono ME, 04469( i% e# C$ Q( R9 n4 G2 f
% 1/26/94
- \; ~) Z3 j& p1 X, w1 j7 {+ Z% Copyright (c) 1996 by Prentice-Hall, Inc. / O/ D! f: T9 F6 w5 h& q' {
* T' U. e, }7 o2 ]. }
[rt,ct]=size(tab);# C* j6 w# n7 J% `# z6 [
if length(val)>1, error('VAL must be a scalar.'), end& S) }0 H7 O$ O) ^, E8 @
if col>ct|col<1, error('Chosen column outside table width.'), end
. `* p* s1 G; x) sif rt<2, error('Table too small or not oriented in columns.'), end* i1 f( o/ p, i# W1 w9 `' f
above=tab(:,col)>val;
7 p& U4 r* x0 s a& c0 L+ b) `below=tab(:,col)<val;
) c. I0 d1 g& h6 G& f& Bequal=tab(:,col)==val;2 q! Z. a5 f! x6 F4 ^
if all(above==0)|all(below==0), % handle simplest case' N; K5 b* P9 n* \5 d( P
y=tab(find(equal), ;1 D( O( ~# q: r8 u. J) Z
return3 J9 C' t3 V/ G5 X
end
4 h8 I; g4 O, a bpslope=find(below(1:rt-1)&above(2:rt)); %indices where slope is pos, k7 _( R! a" n) o
nslope=find(below(2:rt)&above(1:rt-1)); %indices where slope is neg6 }2 w; a* P, \2 l
) g& [% Y, s; q: y3 a; j- P* Sib=sort([pslope;nslope+1]); % put indices below in order
6 T0 d8 U6 t# X5 R! w+ y h4 m( oia=sort([nslope;pslope+1]); % put indices above in order
# l0 ], S2 \, n" v z9 Q5 M- vie=find(equal); % indices where equal to val: `1 {% }9 T& w4 k) o
3 s @7 {$ D% G, Z$ X' `4 e
[tmp,ix]=sort([ib;ie]); % find where equals fit in result+ }2 N6 R, D9 \1 P8 `- d
ieq=ix>length(ib); % True where equals values fit, K* s. m( d; k
ry=length(tmp); % # of rows in result y9 } t* q& l' J- o8 E6 W% W9 Y
, X! u' ^3 F7 C Z1 m( z1 r5 ^y=zeros(ry,ct); % poke data into a zero matrix
s2 [& b% R" i4 p. e" J, G9 Q$ ~4 Q6 }% Y [7 r
alpha=(val-tab(ib,col))./(tab(ia,col)-tab(ib,col));
! l, C# Q- j& `) E. Palpha=alpha(:,ones(1,ct));
! }/ o8 R2 E6 }! v5 Uy(~ieq, =alpha.*tab(ia, +(1-alpha).*tab(ib, ; % interpolated values
# b2 ?: c0 E# U! A( \9 V& M
6 h) ~% R6 {1 Uy(ieq, =tab(ie, ; % equal values8 }) ~2 K( y5 s0 _4 k/ a5 K, y
y(:,col)=val*ones(ry,1); % remove roundoff error |
|