📄 gridfit_demo.html
字号:
<html xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <!--This HTML is auto-generated from an M-file.To make changes, update the M-file and republish this document. --> <title>gridfit_demo</title> <meta name="generator" content="MATLAB 7.0.1"> <meta name="date" content="2006-08-22"> <meta name="m-file" content="gridfit_demo"><style>body { background-color: white; margin:10px;}h1 { color: #990000; font-size: x-large;}h2 { color: #990000; font-size: medium;}p.footer { text-align: right; font-size: xx-small; font-weight: lighter; font-style: italic; color: gray;}pre.codeinput { margin-left: 30px;}span.keyword {color: #0000FF}span.comment {color: #228B22}span.string {color: #A020F0}span.untermstring {color: #B20000}span.syscmd {color: #B28C00}pre.showbuttons { margin-left: 30px; border: solid black 2px; padding: 4px; background: #EBEFF3;}pre.codeoutput { color: gray; font-style: italic;}pre.error { color: red;}/* Make the text shrink to fit narrow windows, but not stretch too far in wide windows. On Gecko-based browsers, the shrink-to-fit doesn't work. */ p,h1,h2,div { /* for MATLAB's browser */ width: 600px; /* for Mozilla, but the "width" tag overrides it anyway */ max-width: 600px; /* for IE */ width:expression(document.body.clientWidth > 620 ? "600px": "auto" );} </style></head> <body> <h2>Contents</h2> <div> <ul> <li><a href="#2">Topographic data</a></li> <li><a href="#4">Fitting a trigonometric surface</a></li> <li><a href="#7">The trig surface with highly different scalings on the x and y axes</a></li> <li><a href="#8">Fitting the "peaks" surface</a></li> <li><a href="#9">Using tiles in gridfit</a></li> </ul> </div><pre class="codeinput"><span class="comment">% Gridfit demo script</span><span class="comment">% This script file is designed to be used in cell mode</span><span class="comment">% from the matlab editor, or best of all, use the publish</span><span class="comment">% to HTML feature from the matlab editor. Older versions</span><span class="comment">% of matlab can copy and paste entire blocks of code into</span><span class="comment">% the Matlab command window.</span></pre><h2>Topographic data<a name="2"></a></h2><pre class="codeinput">load <span class="string">bluff_data</span>;x=bluff_data(:,1);y=bluff_data(:,2);z=bluff_data(:,3);<span class="comment">% Two ravines on a hillside. Scanned from a</span><span class="comment">% topographic map of an area in upstate New York.</span>plot3(x,y,z,<span class="string">'.'</span>)</pre><img vspace="5" hspace="5" src="gridfit_demo_01.png"> <pre class="codeinput"><span class="comment">% Turn the scanned point data into a surface</span>gx=0:4:264;gy=0:4:400;g=gridfit(x,y,z,gx,gy);figurecolormap(hot(256));surf(gx,gy,g);camlight <span class="string">right</span>;lighting <span class="string">phong</span>;shading <span class="string">interp</span>line(x,y,z,<span class="string">'marker'</span>,<span class="string">'.'</span>,<span class="string">'markersize'</span>,4,<span class="string">'linestyle'</span>,<span class="string">'none'</span>);title <span class="string">'Use topographic contours to recreate a surface'</span></pre><img vspace="5" hspace="5" src="gridfit_demo_02.png"> <h2>Fitting a trigonometric surface<a name="4"></a></h2><pre class="codeinput">clearn1 = 15;n2 = 15;theta = rand(n1,1)*pi/2;r = rand(1,n2);x = cos(theta)*r;y = sin(theta)*r;x=x(:);y=y(:);x = [[0 0 1 1]';x;x;1-x;1-x];y = [[0 1 0 1]';y;1-y;y;1-y];figureplot(x,y,<span class="string">'.'</span>)title <span class="string">'Data locations in the x-y plane'</span></pre><img vspace="5" hspace="5" src="gridfit_demo_03.png"> <pre class="codeinput">z = sin(4*x+5*y).*cos(7*(x-y))+exp(x+y);xi = linspace(0,1,51);[xg,yg]=meshgrid(xi,xi);zgd = griddata(x,y,z,xg,yg);figuresurf(xi,xi,zgd)colormap(hot(256))camlight <span class="string">right</span>lighting <span class="string">phong</span>title <span class="string">'Griddata on trig surface'</span><span class="comment">% Note the wing-like artifacts along the edges, due</span><span class="comment">% to the use of a Delaunay triangulation in griddata.</span></pre><img vspace="5" hspace="5" src="gridfit_demo_04.png"> <pre class="codeinput">zgrid = gridfit(x,y,z,xi,xi);figuresurf(xi,xi,zgrid)colormap(hot(256))camlight <span class="string">right</span>lighting <span class="string">phong</span>title(<span class="string">'Gridfit to trig surface'</span>)</pre><img vspace="5" hspace="5" src="gridfit_demo_05.png"> <h2>The trig surface with highly different scalings on the x and y axes<a name="7"></a></h2><pre class="codeinput">xs = x/100;xis = xi/100;ys = y*100;yis = xi*100;<span class="comment">% griddata has problems with badly scaled data</span>[xg,yg]=meshgrid(xis,yis);zgd = griddata(xs,ys,z,xg,yg);figuresurf(xg,yg,zgd)colormap(hot(256))camlight <span class="string">right</span>lighting <span class="string">phong</span>title <span class="string">'Serious problems for griddata on badly scaled trig surface'</span><span class="comment">% autoscaling on (the default)</span>zgrids = gridfit(xs,ys,z,xis,yis,<span class="string">'autoscale'</span>,<span class="string">'on'</span>);<span class="comment">% plot the autoscaled result</span>figuresurf(xis,yis,zgrids)colormap(hot(256))camlight <span class="string">right</span>lighting <span class="string">phong</span>title <span class="string">'Gridfit (automatically scaled) on trig surface'</span></pre><pre class="codeoutput">Warning: Duplicate x-y data points detected: using average of the z values.</pre><img vspace="5" hspace="5" src="gridfit_demo_06.png"> <img vspace="5" hspace="5" src="gridfit_demo_07.png"> <h2>Fitting the "peaks" surface<a name="8"></a></h2><pre class="codeinput">clearn = 100;x = (rand(n,1)-.5)*6;y = (rand(n,1)-.5)*6;z = peaks(x,y);xi = linspace(-3,3,101);zpgf = gridfit(x,y,z,xi,xi);[xg,yg]=meshgrid(xi,xi);zpgd = griddata(x,y,z,xg,yg,<span class="string">'cubic'</span>);figuresurf(xi,xi,zpgd)colormap(jet(256))camlight <span class="string">right</span>lighting <span class="string">phong</span>title <span class="string">'Griddata (method == cubic) on peaks surface'</span>figuresurf(xi,xi,zpgf)colormap(hsv(256))camlight <span class="string">right</span>lighting <span class="string">phong</span>title(<span class="string">'Gridfit to peaks surface'</span>)</pre><img vspace="5" hspace="5" src="gridfit_demo_08.png"> <img vspace="5" hspace="5" src="gridfit_demo_09.png"> <h2>Using tiles in gridfit<a name="9"></a></h2><pre class="codeinput"><span class="comment">% Users of gridfit who have really huge problems now have</span><span class="comment">% an option. I'll generate a large amount of data,</span><span class="comment">% and hope to model a fairly large grid - 800 x 800. This</span><span class="comment">% would normally require gridfit to solve a system of</span><span class="comment">% equations with 640,000 unknowns. It would probably be too</span><span class="comment">% large of a problem for my computer, were I to use gridfit</span><span class="comment">% on the full problem. Gridfit allows you to break the problem</span><span class="comment">% into smaller tiles if you choose. In this case each tile</span><span class="comment">% is 120x120, with a 25% (30 element) overlap between tiles.</span><span class="comment">% Relax, this demo may take a couple of minutes to run!!!!</span>n = 100000;x = rand(n,1);y = rand(n,1);z = x+y+sin((x.^2+y.^2)*10);xnodes = 0:.00125:1;ynodes = xnodes;[zg,xg,yg] = gridfit(x,y,z,xnodes,ynodes,<span class="string">'tilesize'</span>,120,<span class="string">'overlap'</span>,0.25);surf(xg,yg,zg)shading <span class="string">interp</span>colormap(jet(256))camlight <span class="string">right</span>lighting <span class="string">phong</span>title <span class="string">'Tiled gridfit'</span></pre><img vspace="5" hspace="5" src="gridfit_demo_10.png"> <p class="footer"><br> Published with MATLAB® 7.0.1<br></p> <!--##### SOURCE BEGIN #####% Gridfit demo script% This script file is designed to be used in cell mode% from the matlab editor, or best of all, use the publish% to HTML feature from the matlab editor. Older versions% of matlab can copy and paste entire blocks of code into% the Matlab command window.%% Topographic dataload bluff_data;x=bluff_data(:,1);y=bluff_data(:,2);z=bluff_data(:,3);% Two ravines on a hillside. Scanned from a% topographic map of an area in upstate New York.plot3(x,y,z,'.')%%% Turn the scanned point data into a surfacegx=0:4:264;gy=0:4:400;g=gridfit(x,y,z,gx,gy);figurecolormap(hot(256));surf(gx,gy,g);camlight right;lighting phong;shading interpline(x,y,z,'marker','.','markersize',4,'linestyle','none');title 'Use topographic contours to recreate a surface'%% Fitting a trigonometric surfaceclearn1 = 15;n2 = 15;theta = rand(n1,1)*pi/2;r = rand(1,n2);x = cos(theta)*r;y = sin(theta)*r;x=x(:);y=y(:);x = [[0 0 1 1]';x;x;1-x;1-x];y = [[0 1 0 1]';y;1-y;y;1-y];figureplot(x,y,'.')title 'Data locations in the x-y plane'%%z = sin(4*x+5*y).*cos(7*(x-y))+exp(x+y);xi = linspace(0,1,51);[xg,yg]=meshgrid(xi,xi);zgd = griddata(x,y,z,xg,yg);figuresurf(xi,xi,zgd)colormap(hot(256))camlight rightlighting phongtitle 'Griddata on trig surface'% Note the wing-like artifacts along the edges, due% to the use of a Delaunay triangulation in griddata.%%zgrid = gridfit(x,y,z,xi,xi);figuresurf(xi,xi,zgrid)colormap(hot(256))camlight rightlighting phongtitle('Gridfit to trig surface')%% The trig surface with highly different scalings on the x and y axesxs = x/100;xis = xi/100;ys = y*100;yis = xi*100;% griddata has problems with badly scaled data[xg,yg]=meshgrid(xis,yis);zgd = griddata(xs,ys,z,xg,yg);figuresurf(xg,yg,zgd)colormap(hot(256))camlight rightlighting phongtitle 'Serious problems for griddata on badly scaled trig surface'% autoscaling on (the default)zgrids = gridfit(xs,ys,z,xis,yis,'autoscale','on');% plot the autoscaled resultfiguresurf(xis,yis,zgrids)colormap(hot(256))camlight rightlighting phongtitle 'Gridfit (automatically scaled) on trig surface'%% Fitting the "peaks" surfaceclearn = 100;x = (rand(n,1)-.5)*6;y = (rand(n,1)-.5)*6;z = peaks(x,y);xi = linspace(-3,3,101);zpgf = gridfit(x,y,z,xi,xi);[xg,yg]=meshgrid(xi,xi);zpgd = griddata(x,y,z,xg,yg,'cubic');figuresurf(xi,xi,zpgd)colormap(jet(256))camlight rightlighting phongtitle 'Griddata (method == cubic) on peaks surface'figuresurf(xi,xi,zpgf)colormap(hsv(256))camlight rightlighting phongtitle('Gridfit to peaks surface')%% Using tiles in gridfit% Users of gridfit who have really huge problems now have% an option. I'll generate a large amount of data,% and hope to model a fairly large grid - 800 x 800. This% would normally require gridfit to solve a system of% equations with 640,000 unknowns. It would probably be too% large of a problem for my computer, were I to use gridfit% on the full problem. Gridfit allows you to break the problem% into smaller tiles if you choose. In this case each tile% is 120x120, with a 25% (30 element) overlap between tiles.% Relax, this demo may take a couple of minutes to run!!!!n = 100000;x = rand(n,1);y = rand(n,1);z = x+y+sin((x.^2+y.^2)*10);xnodes = 0:.00125:1;ynodes = xnodes;[zg,xg,yg] = gridfit(x,y,z,xnodes,ynodes,'tilesize',120,'overlap',0.25);surf(xg,yg,zg)shading interpcolormap(jet(256))camlight rightlighting phongtitle 'Tiled gridfit'%%##### SOURCE END #####--> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -