source: trunk/src/uvmat_doc/FUNCTIONS_DOC/proj_grid.html @ 37

Last change on this file since 37 was 37, checked in by sommeria, 14 years ago

create_grid.fig ,
uvmat_doc and all the included files added

File size: 10.2 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2                "http://www.w3.org/TR/REC-html40/loose.dtd">
3<html>
4<head>
5  <title>Description of proj_grid</title>
6  <meta name="keywords" content="proj_grid">
7  <meta name="description" content="'proj_grid': project  fields with unstructured coordinantes on a regular grid">
8  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
9  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
10  <meta name="robots" content="index, follow">
11  <link type="text/css" rel="stylesheet" href="../m2html.css">
12</head>
13<body>
14<a name="_top"></a>
15<div><a href="../index.html">Home</a> &gt;  <a href="index.html">.</a> &gt; proj_grid.m</div>
16
17<!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png">&nbsp;Master index</a></td>
18<td align="right"><a href="index.html">Index for .&nbsp;<img alt=">" border="0" src="../right.png"></a></td></tr></table>-->
19
20<h1>proj_grid
21</h1>
22
23<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
24<div class="box"><strong>'proj_grid': project  fields with unstructured coordinantes on a regular grid</strong></div>
25
26<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
27<div class="box"><strong>function [A,rangx,rangy]=proj_grid(vec_X,vec_Y,vec_A,rgx_in,rgy_in,npxy_in) </strong></div>
28
29<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
30<div class="fragment"><pre class="comment">'proj_grid': project  fields with unstructured coordinantes on a regular grid
31 -------------------------------------------------------------------------
32 function [A,rangx,rangy]=proj_grid(vec_X,vec_Y,vec_A,rgx_in,rgy_in,npxy_in)</pre></div>
33
34<!-- crossreference -->
35<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
36This function calls:
37<ul style="list-style-image:url(../matlabicon.gif)">
38<li><a href="griddata_uvmat.html" class="code" title="function ZI = griddata_uvmat(X,Y,Z,XI,YI)">griddata_uvmat</a>     'griddata_uvmat': function griddata_uvmat(vec2_X,vec2_Y,vec2_U,vec_X,vec_Y,'linear')</li><li><a href="warndlg_uvmat.html" class="code" title="function hwarn=warndlg_uvmat(warntext,title)">warndlg_uvmat</a>   'warndlg_uvmat': display warning message (error, warning, confirmation) in a given figure</li></ul>
39This function is called by:
40<ul style="list-style-image:url(../matlabicon.gif)">
41<li><a href="plot_field.html" class="code" title="function [PlotType,PlotParamOut,haxes]= plot_field(Data,haxes,PlotParam,KeepLim,PosColorbar)">plot_field</a>  'plot_field': plot any field with the structure defined in the uvmat package</li><li><a href="sub_field.html" class="code" title="function SubData=sub_field(UvData,Field);">sub_field</a>      'sub_field': combines two input fields + mask for uvmat</li></ul>
42<!-- crossreference -->
43
44
45<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
46<div class="fragment"><pre>0001 <span class="comment">%'proj_grid': project  fields with unstructured coordinantes on a regular grid</span>
470002 <span class="comment">% -------------------------------------------------------------------------</span>
480003 <span class="comment">% function [A,rangx,rangy]=proj_grid(vec_X,vec_Y,vec_A,rgx_in,rgy_in,npxy_in)</span>
490004
500005
510006 <a name="_sub0" href="#_subfunctions" class="code">function [A,rangx,rangy]=proj_grid(vec_X,vec_Y,vec_A,rgx_in,rgy_in,npxy_in)</a>
520007     <span class="keyword">if</span> length(vec_Y)&lt;2
530008         <a href="warndlg_uvmat.html" class="code" title="function hwarn=warndlg_uvmat(warntext,title)">warndlg_uvmat</a>(<span class="string">'less than 2 points in proj_grid.m'</span>,<span class="string">'ERROR'</span>);
540009         <span class="keyword">return</span>;
550010     <span class="keyword">end</span>
560011     diffy=diff(vec_Y); <span class="comment">%difference dy=vec_Y(i+1)-vec_Y(i)</span>
570012     index=find(diffy);<span class="comment">% find the indices of vec_Y after wich a change of horizontal line occurs(diffy non zero)</span>
580013     <span class="keyword">if</span> isempty(index); <a href="warndlg_uvmat.html" class="code" title="function hwarn=warndlg_uvmat(warntext,title)">warndlg_uvmat</a>(<span class="string">'points aligned along abscissa in proj_grid.m'</span>,<span class="string">'ERROR'</span>); <span class="keyword">return</span>; <span class="keyword">end</span>;<span class="comment">%points aligned% A FAIRE: switch to line plot.</span>
590014     diff2=diff(diffy(index));<span class="comment">% diff2 = fluctuations of the detected vertical grid mesh dy</span>
600015     <span class="keyword">if</span> max(abs(diff2))&gt;0.001*abs(diffy(index(1))) <span class="comment">% if max(diff2) is larger than 1/1000 of the first mesh dy</span>
610016         <span class="comment">% the data are not regularly spaced and must be interpolated  on a regular grid</span>
620017         <span class="keyword">if</span> exist(<span class="string">'rgx_in'</span>,<span class="string">'var'</span>) &amp; ~isempty (rgx_in) &amp; isnumeric(rgx_in) &amp; length(rgx_in)==2<span class="comment">%  positions imposed from input</span>
630018             rangx=rgx_in; <span class="comment">% first and last positions</span>
640019             rangy=rgy_in;
650020 <span class="comment">%             npxy=npxy_in;</span>
660021             dxy(1)=1/(npxy_in(1)-1);<span class="comment">%grid mesh in y</span>
670022             dxy(2)=1/(npxy_in(2)-1);<span class="comment">%grid mesh in x</span>
680023             dxy(1)=(rangy(2)-rangy(1))/(npxy_in(1)-1);<span class="comment">%grid mesh in y</span>
690024             dxy(2)=(rangx(2)-rangx(1))/(npxy_in(2)-1);<span class="comment">%grid mesh in x</span>
700025         <span class="keyword">else</span> <span class="comment">% interpolation grid automatically determined</span>
710026             rangx(1)=min(vec_X);
720027             rangx(2)=max(vec_X);
730028             rangy(2)=min(vec_Y);
740029             rangy(1)=max(vec_Y);
750030             dxymod=sqrt((rangx(2)-rangx(1))*(rangy(1)-rangy(2))/length(vec_X));
760031             dxy=[-dxymod/4 dxymod/4];<span class="comment">% increase the resolution 4 times</span>
770032         <span class="keyword">end</span>
780033         xi=[rangx(1):dxy(2):rangx(2)];
790034         yi=[rangy(1):dxy(1):rangy(2)];
800035         [XI,YI]=meshgrid(xi,yi);<span class="comment">% creates the matrix of regular coordinates</span>
810036         A=<a href="griddata_uvmat.html" class="code" title="function ZI = griddata_uvmat(X,Y,Z,XI,YI)">griddata_uvmat</a>(vec_X,vec_Y,vec_A,xi,yi');
820037         A=reshape(A,length(yi),length(xi));
830038     <span class="keyword">else</span>
840039         x=vec_X(1:index(1));<span class="comment">% the set of abscissa (obtained on the first line)</span>
850040         indexend=index(end);<span class="comment">% last vector index of line change</span>
860041         ymax=vec_Y(indexend+1);<span class="comment">% y coordinate AFTER line change</span>
870042         ymin=vec_Y(index(1));
880043         <span class="comment">%y=[vec_Y(index) ymax]; % the set of y ordinates including the last one</span>
890044         y=vec_Y(index);
900045         y(length(y)+1)=ymax;
910046         nx=length(x);   <span class="comment">%number of grid points in x</span>
920047         ny=length(y);   <span class="comment">% number of grid points in y</span>
930048         B=(reshape(vec_A,nx,ny))'; <span class="comment">%vec_A reshaped as a rectangular matrix</span>
940049         [X,Y]=meshgrid(x,y);<span class="comment">% positions X and Y also reshaped as matrix</span>
950050         
960051         <span class="comment">%linear interpolation to improve the image resolution and/or adjust</span>
970052         <span class="comment">%to prescribed positions</span>
980053         test_interp=1;
990054         <span class="keyword">if</span> exist(<span class="string">'rgx_in'</span>,<span class="string">'var'</span>) &amp; ~isempty (rgx_in) &amp; isnumeric(rgx_in) &amp; length(rgx_in)==2<span class="comment">%  positions imposed from input</span>
1000055             rangx=rgx_in; <span class="comment">% first and last positions</span>
1010056             rangy=rgy_in;
1020057             npxy=npxy_in;
1030058         <span class="keyword">else</span>       
1040059             rangx=[vec_X(1) vec_X(nx)];<span class="comment">% first and last position found for x</span>
1050060 <span class="comment">%             rangy=[ymin ymax];</span>
1060061               rangy=[max(ymax,ymin) min(ymax,ymin)];
1070062             <span class="keyword">if</span> max(nx,ny) &lt;= 64 &amp; isequal(npxy_in,<span class="string">'np&gt;256'</span>)
1080063                 npxy=[8*ny 8*nx];<span class="comment">% increase the resolution 8 times</span>
1090064             <span class="keyword">elseif</span> max(nx,ny) &lt;= 128 &amp; isequal(npxy_in,<span class="string">'np&gt;256'</span>)
1100065                 npxy=[4*ny 4*nx];<span class="comment">% increase the resolution 4 times</span>
1110066             <span class="keyword">elseif</span> max(nx,ny) &lt;= 256 &amp; isequal(npxy_in,<span class="string">'np&gt;256'</span>)
1120067                 npxy=[2*ny 2*nx];<span class="comment">% increase the resolution 2 times</span>
1130068             <span class="keyword">else</span>
1140069                 npxy=[ny nx];
1150070                 test_interp=0; <span class="comment">% no interpolation done</span>
1160071             <span class="keyword">end</span>
1170072         <span class="keyword">end</span>
1180073         <span class="keyword">if</span> test_interp==1<span class="comment">%if we interpolate</span>
1190074             xi=[rangx(1):(rangx(2)-rangx(1))/(npxy(2)-1):rangx(2)];
1200075             yi=[rangy(1):(rangy(2)-rangy(1))/(npxy(1)-1):rangy(2)];
1210076             [XI,YI]=meshgrid(xi,yi);
1220077             A = interp2(X,Y,B,XI,YI);
1230078         <span class="keyword">else</span> <span class="comment">%no interpolation for a resolution higher than 256</span>
1240079             A=B;
1250080             XI=X;
1260081             YI=Y;
1270082         <span class="keyword">end</span>
1280083     <span class="keyword">end</span></pre></div>
129<hr><address>Generated on Fri 13-Nov-2009 11:17:03 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
130</body>
131</html>
Note: See TracBrowser for help on using the repository browser.