- 在线时间
- 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)
3 S2 m6 J/ R s* Z( O2 K%MMINTERP 1-D Table Search by Linear Interpolation.% N9 k& F0 H* p* t( ~
% Y=MMINTERP(TAB,COL,VAL) linearly interpolates the table
% n1 ~' c9 \! T: Z% TAB searching for the scalar value VAL in the column COL.
% _7 x# b/ T0 V0 c# b' B% All crossings are found and TAB(:,COL) need not be monotonic.
J9 o" a+ t4 I! `4 F, W% Each crossing is returned as a separate row in Y and Y has as7 q4 a9 n* k N8 k. f
% many columns as TAB. Naturally, the column COL of Y contains; h- K4 s; S: N& \
% the value VAL. If VAL is not found in the table, Y=[].2 l1 u( d. \( U- |
- v) G1 l q8 Y0 b; H6 {* _
% D.C. Hanselman, University of Maine, Orono ME, 04469
, [- N1 ]1 ?/ G( i& v% 1/26/94
3 u3 Q# I# H; C1 V, K* _' `% Copyright (c) 1996 by Prentice-Hall, Inc. 9 ]" E4 u4 |- Z
0 f: r" J7 T9 {. D; J3 n[rt,ct]=size(tab);$ G" F) Y1 @9 A4 m* R
if length(val)>1, error('VAL must be a scalar.'), end, p/ r) r6 {& H, N! U/ j
if col>ct|col<1, error('Chosen column outside table width.'), end( K# Z& U! [/ ^% U# O& g
if rt<2, error('Table too small or not oriented in columns.'), end% g R5 t w/ U3 `+ r
above=tab(:,col)>val;: n% s% |5 E! e- o3 G$ B. M% j1 h
below=tab(:,col)<val;
5 |$ G' h+ R6 f. L8 I3 D# |equal=tab(:,col)==val;
( @/ ^5 U* r5 v* [% xif all(above==0)|all(below==0), % handle simplest case; } \7 o3 r- E2 l j3 I8 N
y=tab(find(equal), ;- \- O. E! l% Z6 r
return
& Z" J6 U* h" G* j+ |% S! k% Hend7 v; ^9 g& l" S- `
pslope=find(below(1:rt-1)&above(2:rt)); %indices where slope is pos
$ w$ e7 t* Y2 C# F2 [5 Jnslope=find(below(2:rt)&above(1:rt-1)); %indices where slope is neg/ e* Z: e( w! z8 S n
. e1 F6 a0 k" | n7 e D; `
ib=sort([pslope;nslope+1]); % put indices below in order9 z% i. {6 H% u; N& M0 p
ia=sort([nslope;pslope+1]); % put indices above in order9 O6 Z5 r$ d# U0 A% F7 L `
ie=find(equal); % indices where equal to val
5 f D4 X6 g+ ?
& ?# R9 K2 H, X, s* m. z% h7 B[tmp,ix]=sort([ib;ie]); % find where equals fit in result4 @: [2 _9 f) {: e# F: z
ieq=ix>length(ib); % True where equals values fit
: F1 N# k' H5 L; A# e! p# Iry=length(tmp); % # of rows in result y, I7 d1 Z% l7 |: A
5 M% G2 z. {6 E1 C6 T, `3 ny=zeros(ry,ct); % poke data into a zero matrix9 j2 O6 z+ a6 [5 s9 ]# D5 v" k
& n( Z% Z7 N, L2 f, K" ^3 q+ }# {2 [alpha=(val-tab(ib,col))./(tab(ia,col)-tab(ib,col));* `: v0 d; [$ F5 M
alpha=alpha(:,ones(1,ct));! r+ A8 S) j) y9 V+ }. s# d) |6 I
y(~ieq, =alpha.*tab(ia, +(1-alpha).*tab(ib, ; % interpolated values2 E& e. P9 W8 u
: J) z% B; D Hy(ieq, =tab(ie, ; % equal values7 @9 S+ h* I1 N0 N
y(:,col)=val*ones(ry,1); % remove roundoff error |
|