function interpgui(arg1,arg2)
%INTERPGUI Behavior of interpolating functions.
% Demonstrates interpolation by a piecewise linear interpolant,
% a polynomial, a spline, and a shape preserving Hermite cubic.
% INTERPGUI(x,y) starts with a plot of y vs. x.
% INTERPGUI(y) starts with equally spaced x's.
% INTERPGUI(n) starts with y = zeros(1,n).
% INTERPGUI with no arguments starts with eight zeros.
% The interpolation points can be varied with the mouse.
% If x is specified, it remains fixed.
%
% See also SPLINETX, PCHIPTX, POLYINTERP, PIECELIN. if nargin == 0 | isnumeric(arg1) % Interpret arguments if nargin == 0
% interpgui with no arguments
n = 8;
x = 1:n;
y = zeros(1,n);
elseif length(arg1) == 1
% interpgui(n)
n = arg1;
x = 1:n;
y = zeros(1,n);
elseif nargin == 1
% interpgui(y)
n = length(arg1);
x = 1:n;
y = arg1(:)';
elseif length(arg1) == length(arg2)
% interpgui(x,y)
[x,k] = sort(arg1(:)');
y = arg2(k)';
else
error('Two arguments must have same length')
end
arg1 = []; % Initialize figure shg
clf reset
set(gcf,'doublebuffer','on', ...
'name','Interp gui', 'numbertitle','off', ...
'windowbuttondown',['interpgui(''move''); set(gcf,' ...
'''windowbuttonmotion'',''interpgui(''''move'''')'')'], ...
'windowbuttonup','set(gcf,''windowbuttonmotion'','''')'); % Initialize plots n = length(x);
h = diff(x);
u = zeros(1,128*(n+1));
j = 1:128;
s = (1+sin((j-65)/128*pi))/2;
u(j) = x(1)+(s-1)*h(1);
for k = 1:n-1
u(128*k+j) = x(k)+s*h(k);
end
u(128*n+j) = x(n)+s*h(n-1);
p = plot(x,y,'o',u,zeros(4,length(u)),'-');
ymin = min(y);
ymax = max(y);
ydel = ymax-ymin;
if ydel == 0; ydel = 1; end
axis([min(u) max(u) ymin-0.5*ydel ymax+0.5*ydel])
title('Interpolation') % Controls uicontrol('units','normal','pos',[.68 .13 .12 .18], ...
'style','frame','background','white')
F = {'linear','poly','spline','pchip'};
pos = [.69 .26 .09 .04];
vis = 0;
for k = 1:4
uicontrol('units','normal','pos',pos, ...
'style','check','string',F{k},'value',vis, ...
'background','white','foreground',get(p(k+1),'color'), ...
'callback','interpgui(''cb'')');
pos(2) = pos(2)-.04;
end
uicontrol('units','normal','pos',[.85 .01 .10 .06], ...
'style','push','string','close','tag','reset/close', ...
'callback','close(gcf)'); % Remember original data xfree = (nargin < 2);
set(gcf,'userdata',xfree)
set(gca,'userdata',{x,y})
end p = flipud(get(gca,'children'));
x = get(p(1),'xdata');
y = get(p(1),'ydata');
n = length(x);
h = diff(x);
u = zeros(1,128*(n+1));
j = 1:128;
s = (1+sin((j-65)/128*pi))/2;
u(j) = x(1)+(s-1)*h(1);
for k = 1:n-1
u(128*k+j) = x(k)+s*h(k);
end
u(128*n+j) = x(n)+s*h(n-1); if isequal(arg1,'reset') % Restore original data xy = get(gca,'userdata');
x = xy{1};
y = xy{2};
set(findobj('tag','reset/close'),'string','close', ...
'callback','close(gcf)'); elseif isequal(arg1,'move') % Respond to mouse motion z = get(gca,'currentpoint');
z = z(1,:);
p = flipud(get(gca,'children'));
e = abs(x-z(1));
k = min(find(e == min(e)));
xfree = get(gcf,'userdata');
if xfree
x(k) = z(1);
end
y(k) = z(2);
set(findobj('tag','reset/close'),'string','reset', ...
'callback','interpgui(''reset'')'); end ax = axis;
set(p(1),'xdata',x,'ydata',y)
set(p(2),'xdata',u,'ydata',piecelin(x,y,u));
set(p(3),'xdata',u,'ydata',polyinterp(x,y,u));
set(p(4),'xdata',u,'ydata',splinetx(x,y,u));
set(p(5),'xdata',u,'ydata',pchiptx(x,y,u));
axis(ax); % Visibility b = flipud(get(gcf,'children'));
onf = {'off','on'};
for k = 1:4
% Interpolants
set(p(k+1),'visible',onf{get(b(k+2),'value')+1})
end

Matlab interpgui的更多相关文章

  1. Matlab 绘制三维立体图(以地质异常体为例)

    前言:在地球物理勘探,流体空间分布等多种场景中,定位空间点P(x,y,x)的物理属性值Q,并绘制三维空间分布图,对我们洞察空间场景有十分重要的意义. 1. 三维立体图的基本要件: 全空间网格化 网格节 ...

  2. Matlab slice方法和包络法绘制三维立体图

    前言:在地球物理勘探,流体空间分布等多种场景中,定位空间点P(x,y,x)的物理属性值Q,并绘制三维空间分布图,对我们洞察空间场景有十分重要的意义. 1. 三维立体图的基本要件: 全空间网格化 网格节 ...

  3. Matlab 高斯_拉普拉斯滤波器处理医学图像

    前言:本程序是我去年实现论文算法时所做.主要功能为标记切割肝脏区域.时间有点久,很多细节已经模糊加上代码做了很多注释,因此在博客中不再详述. NOTE: 程序分几大段功能模块,仔细阅读,对解决医学图像 ...

  4. MATLAB中绘制质点轨迹动图并保存成GIF

    工作需要在MATLAB中绘制质点轨迹并保存成GIF以便展示. 绘制质点轨迹动图可用comet和comet3命令,使用例子如下: t = 0:.01:2*pi;x = cos(2*t).*(cos(t) ...

  5. linux下配置matlab运行环境(MCR)

    在安装好的matlab下有MCR(MatlabCompilerRuntime)在matlab2011/toolbox/compiler/deploy/glnxa64下找到MCRInstaller.zi ...

  6. EMD分析 Matlab 精华总结 附开源工具箱(全)

    前言: 本贴写于2016年12与15日,UK.最近在学习EMD(Empirical Mode Decomposition)和HHT(Hilbert-Huang Transform)多分辨信号处理,FQ ...

  7. Atitit MATLAB 图像处理 经典书籍attilax总结

    Atitit MATLAB 图像处理 经典书籍attilax总结 1.1. MATLAB数字图像处理1 1.2. <MATLAB实用教程(第二版)>((美)穆尔 著)[简介_书评_在线阅读 ...

  8. Atitit MATLAB 图像处理attilax总结

    Atitit MATLAB 图像处理attilax总结 1.1. 下载 Matlab7.0官方下载_Matlab2012 v7.0 官方简体中文版-办公软件-系统大全.html1 1.2. Matla ...

  9. Atitit java c# php c++ js跨语言调用matlab实现边缘检测等功能attilax总结

    Atitit java c# php c++ js跨语言调用matlab实现边缘检测等功能attilax总结 1.1. 边缘检测的基本方法Canny最常用了1 1.2. 编写matlab边缘检测代码, ...

随机推荐

  1. 【树形DP】BZOJ1596-[Usaco2008 Jan]电话网络

    [题目大意] 在一棵有n个节点的树上建信号塔,每个节点的信号塔可以覆盖当前节点极其相连的节点.问要覆盖所有节点,至少需要多少座信号塔? [思路] 经典的树形DP,直接复制一下. f[i][0]:以i为 ...

  2. 51nod1675 序列变换

    link 题意: 给定长为n的序列a,b,下标从1开始,问有多少对x,y满足gcd(x,y)=1且$a_{b_x}=b_{a_y}$? $n\leq 10^5.$ 题解: $a_{b_x}$和$b_{ ...

  3. hdu 3681 压缩dp+搜索

    题意:一个机器人想越狱,他只能带一定电量的电池,'S'表示道路可行,'G'表示充电器, 只可充电一次,但是可以经过很多次.'F'表示起点,'Y'表示要破坏的机关,也是只能破坏一次,但是可以经过无数次. ...

  4. web前端 -- 页面设计小技巧

    1:进入网页时淡入淡出的效果. <meta http-equiv=”Page-Exit”; content=”blendTrans(Duration=1.0)”> 在头部head之间加入此 ...

  5. MOSFET pair makes simple SPDT switch

    With an n- and p-channel MOSFET, you can easily implement a single-pole double-throw (SPDT) switch t ...

  6. JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式

    JSON JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式. 它基于JavaScript(Standard ECMA-262 3rd Edition - D ...

  7. 了解你的Linux系统:必须掌握的20个命令

    转载:http://blog.chinaunix.net/uid-16459552-id-3877787.html 要想详细了解你的Linux系统,为系统评估和性能调化提供准确的信息,那么,你会经常用 ...

  8. thinkphp输出表格

    //这是打印5列n行的表格,所以mod="5" value="4" <tr> <volist name="data" id ...

  9. 返回content-length=0问题解决

    遇到一个奇怪问题,有时候会不显示css或图片文件,通过调试工具发现请求返回长度都是0.研究半天未果,初步猜测可能是过滤器给拦截了. 果然在一个过滤器中发现相关代码: HttpRequestWrappe ...

  10. 谈谈Copy-on-Write容器

    1.简介 Copy-On-Write简称COW,是一种用于程序设计中的优化策略.其基本思路是,从一开始大家都在共享同一个内容,当某个人想要修改这个内容的时候,才会真正把内容Copy出去形成一个新的内容 ...