- 在线时间
- 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)
) s# ~, y- ]0 P" l8 J%MMINTERP 1-D Table Search by Linear Interpolation.
- ~8 B+ p3 l! X8 R1 Q+ y* |% Y=MMINTERP(TAB,COL,VAL) linearly interpolates the table
* \. k" N; M4 w- W; {) J% TAB searching for the scalar value VAL in the column COL.
! o% F2 n$ F1 \4 b# d9 o9 X% All crossings are found and TAB(:,COL) need not be monotonic.5 ~& x& H7 [6 B
% Each crossing is returned as a separate row in Y and Y has as0 |8 \& T' S: x0 E# a: Z
% many columns as TAB. Naturally, the column COL of Y contains
2 } d' L% Q$ `, }/ D% the value VAL. If VAL is not found in the table, Y=[].
+ G7 ]; a' F/ W; r
3 m8 y/ b) j+ O9 A, a/ [6 ?$ ]% D.C. Hanselman, University of Maine, Orono ME, 04469
' y0 C* U, k; q2 l: S* V% 1/26/94
7 t9 f" ^: x* L1 S# D, P7 c; F% Copyright (c) 1996 by Prentice-Hall, Inc. & }5 t9 t0 K6 e" q6 F
- m7 Y6 x A5 c9 ?0 v[rt,ct]=size(tab);
; K4 h1 I4 e, O D, s( E+ ~! j7 }if length(val)>1, error('VAL must be a scalar.'), end
/ j$ @& ]0 O& K* H( hif col>ct|col<1, error('Chosen column outside table width.'), end5 n7 }, @6 ?7 Q: G
if rt<2, error('Table too small or not oriented in columns.'), end+ L& N' U9 w" O3 }7 {% r. x
above=tab(:,col)>val;% y& @/ ?0 O, n8 p) M5 k' ~+ ~1 R
below=tab(:,col)<val;
( Y: G/ p2 Y( [1 s/ {; Dequal=tab(:,col)==val;
& k: j5 U" C6 Nif all(above==0)|all(below==0), % handle simplest case5 N! _5 L# p0 o! o. I
y=tab(find(equal), ;# v% k: u: w. t
return. ^0 {$ h0 g" G# i+ X, B) y- [
end
* I Q: G9 ?5 K4 v* y5 g/ ^* i! ^3 Zpslope=find(below(1:rt-1)&above(2:rt)); %indices where slope is pos
% _& ?2 H( I' inslope=find(below(2:rt)&above(1:rt-1)); %indices where slope is neg
7 w6 g9 B4 N& `! Z4 e9 h
9 \ X" Y" }+ i8 |# V7 i! lib=sort([pslope;nslope+1]); % put indices below in order4 Q8 \2 U" q- s2 G, t: U5 S, H0 i9 z
ia=sort([nslope;pslope+1]); % put indices above in order9 p- S% W9 i7 L: ?* D
ie=find(equal); % indices where equal to val: N' C- y, e7 _) p, {7 p; c# c
2 F' S; N8 ~/ ~- O. F/ J6 Y! |[tmp,ix]=sort([ib;ie]); % find where equals fit in result
1 W% ~0 f/ Y9 [( t' O f+ _& ]ieq=ix>length(ib); % True where equals values fit
8 G* n$ R; D0 q, `3 h6 @ry=length(tmp); % # of rows in result y
) R+ o0 ^0 ~7 e* W; w
5 R) G7 v8 n4 c% w* ]/ Xy=zeros(ry,ct); % poke data into a zero matrix
1 O% F3 k3 h+ t, C& ?2 ]6 j Y- l+ l. o X! W
alpha=(val-tab(ib,col))./(tab(ia,col)-tab(ib,col));: N2 q% P+ D: ^9 A+ l
alpha=alpha(:,ones(1,ct));
0 P! N/ I l6 ^! O6 ?* f) vy(~ieq, =alpha.*tab(ia, +(1-alpha).*tab(ib, ; % interpolated values# h L+ N7 D5 n& n: O7 f
( P% K8 s7 N( Dy(ieq, =tab(ie, ; % equal values* T7 j0 c" i1 B( u
y(:,col)=val*ones(ry,1); % remove roundoff error |
|