[37] | 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 © 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> > <a href="index.html">.</a> > proj_grid.m</div> |
---|
| 16 | |
---|
| 17 | <!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png"> Master index</a></td> |
---|
| 18 | <td align="right"><a href="index.html">Index for . <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> |
---|
| 36 | This 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> |
---|
| 39 | This 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> |
---|
| 47 | 0002 <span class="comment">% -------------------------------------------------------------------------</span> |
---|
| 48 | 0003 <span class="comment">% function [A,rangx,rangy]=proj_grid(vec_X,vec_Y,vec_A,rgx_in,rgy_in,npxy_in)</span> |
---|
| 49 | 0004 |
---|
| 50 | 0005 |
---|
| 51 | 0006 <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> |
---|
| 52 | 0007 <span class="keyword">if</span> length(vec_Y)<2 |
---|
| 53 | 0008 <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>); |
---|
| 54 | 0009 <span class="keyword">return</span>; |
---|
| 55 | 0010 <span class="keyword">end</span> |
---|
| 56 | 0011 diffy=diff(vec_Y); <span class="comment">%difference dy=vec_Y(i+1)-vec_Y(i)</span> |
---|
| 57 | 0012 index=find(diffy);<span class="comment">% find the indices of vec_Y after wich a change of horizontal line occurs(diffy non zero)</span> |
---|
| 58 | 0013 <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> |
---|
| 59 | 0014 diff2=diff(diffy(index));<span class="comment">% diff2 = fluctuations of the detected vertical grid mesh dy</span> |
---|
| 60 | 0015 <span class="keyword">if</span> max(abs(diff2))>0.001*abs(diffy(index(1))) <span class="comment">% if max(diff2) is larger than 1/1000 of the first mesh dy</span> |
---|
| 61 | 0016 <span class="comment">% the data are not regularly spaced and must be interpolated on a regular grid</span> |
---|
| 62 | 0017 <span class="keyword">if</span> exist(<span class="string">'rgx_in'</span>,<span class="string">'var'</span>) & ~isempty (rgx_in) & isnumeric(rgx_in) & length(rgx_in)==2<span class="comment">% positions imposed from input</span> |
---|
| 63 | 0018 rangx=rgx_in; <span class="comment">% first and last positions</span> |
---|
| 64 | 0019 rangy=rgy_in; |
---|
| 65 | 0020 <span class="comment">% npxy=npxy_in;</span> |
---|
| 66 | 0021 dxy(1)=1/(npxy_in(1)-1);<span class="comment">%grid mesh in y</span> |
---|
| 67 | 0022 dxy(2)=1/(npxy_in(2)-1);<span class="comment">%grid mesh in x</span> |
---|
| 68 | 0023 dxy(1)=(rangy(2)-rangy(1))/(npxy_in(1)-1);<span class="comment">%grid mesh in y</span> |
---|
| 69 | 0024 dxy(2)=(rangx(2)-rangx(1))/(npxy_in(2)-1);<span class="comment">%grid mesh in x</span> |
---|
| 70 | 0025 <span class="keyword">else</span> <span class="comment">% interpolation grid automatically determined</span> |
---|
| 71 | 0026 rangx(1)=min(vec_X); |
---|
| 72 | 0027 rangx(2)=max(vec_X); |
---|
| 73 | 0028 rangy(2)=min(vec_Y); |
---|
| 74 | 0029 rangy(1)=max(vec_Y); |
---|
| 75 | 0030 dxymod=sqrt((rangx(2)-rangx(1))*(rangy(1)-rangy(2))/length(vec_X)); |
---|
| 76 | 0031 dxy=[-dxymod/4 dxymod/4];<span class="comment">% increase the resolution 4 times</span> |
---|
| 77 | 0032 <span class="keyword">end</span> |
---|
| 78 | 0033 xi=[rangx(1):dxy(2):rangx(2)]; |
---|
| 79 | 0034 yi=[rangy(1):dxy(1):rangy(2)]; |
---|
| 80 | 0035 [XI,YI]=meshgrid(xi,yi);<span class="comment">% creates the matrix of regular coordinates</span> |
---|
| 81 | 0036 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'); |
---|
| 82 | 0037 A=reshape(A,length(yi),length(xi)); |
---|
| 83 | 0038 <span class="keyword">else</span> |
---|
| 84 | 0039 x=vec_X(1:index(1));<span class="comment">% the set of abscissa (obtained on the first line)</span> |
---|
| 85 | 0040 indexend=index(end);<span class="comment">% last vector index of line change</span> |
---|
| 86 | 0041 ymax=vec_Y(indexend+1);<span class="comment">% y coordinate AFTER line change</span> |
---|
| 87 | 0042 ymin=vec_Y(index(1)); |
---|
| 88 | 0043 <span class="comment">%y=[vec_Y(index) ymax]; % the set of y ordinates including the last one</span> |
---|
| 89 | 0044 y=vec_Y(index); |
---|
| 90 | 0045 y(length(y)+1)=ymax; |
---|
| 91 | 0046 nx=length(x); <span class="comment">%number of grid points in x</span> |
---|
| 92 | 0047 ny=length(y); <span class="comment">% number of grid points in y</span> |
---|
| 93 | 0048 B=(reshape(vec_A,nx,ny))'; <span class="comment">%vec_A reshaped as a rectangular matrix</span> |
---|
| 94 | 0049 [X,Y]=meshgrid(x,y);<span class="comment">% positions X and Y also reshaped as matrix</span> |
---|
| 95 | 0050 |
---|
| 96 | 0051 <span class="comment">%linear interpolation to improve the image resolution and/or adjust</span> |
---|
| 97 | 0052 <span class="comment">%to prescribed positions</span> |
---|
| 98 | 0053 test_interp=1; |
---|
| 99 | 0054 <span class="keyword">if</span> exist(<span class="string">'rgx_in'</span>,<span class="string">'var'</span>) & ~isempty (rgx_in) & isnumeric(rgx_in) & length(rgx_in)==2<span class="comment">% positions imposed from input</span> |
---|
| 100 | 0055 rangx=rgx_in; <span class="comment">% first and last positions</span> |
---|
| 101 | 0056 rangy=rgy_in; |
---|
| 102 | 0057 npxy=npxy_in; |
---|
| 103 | 0058 <span class="keyword">else</span> |
---|
| 104 | 0059 rangx=[vec_X(1) vec_X(nx)];<span class="comment">% first and last position found for x</span> |
---|
| 105 | 0060 <span class="comment">% rangy=[ymin ymax];</span> |
---|
| 106 | 0061 rangy=[max(ymax,ymin) min(ymax,ymin)]; |
---|
| 107 | 0062 <span class="keyword">if</span> max(nx,ny) <= 64 & isequal(npxy_in,<span class="string">'np>256'</span>) |
---|
| 108 | 0063 npxy=[8*ny 8*nx];<span class="comment">% increase the resolution 8 times</span> |
---|
| 109 | 0064 <span class="keyword">elseif</span> max(nx,ny) <= 128 & isequal(npxy_in,<span class="string">'np>256'</span>) |
---|
| 110 | 0065 npxy=[4*ny 4*nx];<span class="comment">% increase the resolution 4 times</span> |
---|
| 111 | 0066 <span class="keyword">elseif</span> max(nx,ny) <= 256 & isequal(npxy_in,<span class="string">'np>256'</span>) |
---|
| 112 | 0067 npxy=[2*ny 2*nx];<span class="comment">% increase the resolution 2 times</span> |
---|
| 113 | 0068 <span class="keyword">else</span> |
---|
| 114 | 0069 npxy=[ny nx]; |
---|
| 115 | 0070 test_interp=0; <span class="comment">% no interpolation done</span> |
---|
| 116 | 0071 <span class="keyword">end</span> |
---|
| 117 | 0072 <span class="keyword">end</span> |
---|
| 118 | 0073 <span class="keyword">if</span> test_interp==1<span class="comment">%if we interpolate</span> |
---|
| 119 | 0074 xi=[rangx(1):(rangx(2)-rangx(1))/(npxy(2)-1):rangx(2)]; |
---|
| 120 | 0075 yi=[rangy(1):(rangy(2)-rangy(1))/(npxy(1)-1):rangy(2)]; |
---|
| 121 | 0076 [XI,YI]=meshgrid(xi,yi); |
---|
| 122 | 0077 A = interp2(X,Y,B,XI,YI); |
---|
| 123 | 0078 <span class="keyword">else</span> <span class="comment">%no interpolation for a resolution higher than 256</span> |
---|
| 124 | 0079 A=B; |
---|
| 125 | 0080 XI=X; |
---|
| 126 | 0081 YI=Y; |
---|
| 127 | 0082 <span class="keyword">end</span> |
---|
| 128 | 0083 <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> © 2003</address> |
---|
| 130 | </body> |
---|
| 131 | </html> |
---|