Changeset 179 for trunk/src/sub_field.m
- Timestamp:
- Jan 9, 2011, 12:56:28 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sub_field.m
r165 r179 1 %'sub_field': combines two input fields 1 %'sub_field': combines two input fields 2 % 3 % the two fields are subtstracted when of the same nature (scalar or 4 % vector), if the coordinates do not coincide, the second field is 5 % interpolated on the cooridintes of the first one 6 % 7 % when scalar and vectors are combined, the fields are just merged in a single matlab structure for common visualisation 2 8 %----------------------------------------------------------------------- 3 9 % function SubData=sub_field(Field,Field_1) … … 7 13 % 8 14 % INPUT: 9 % UvData: main structure UvData associated to the uvmat GUI as 'UserData' 10 % Field: cell of Matlab structures representing the input fields 11 % 12 % -- TODO: need to be rationalized -- 15 % Field: matlab structure representing the first field 16 % Field_1:matlab structure representing the second field 13 17 14 18 function [SubData,errormsg]=sub_field(Field,Field_1) … … 77 81 return 78 82 end 79 % VarIndex=CellVarIndex{iselect};80 % VarIndex_1=CellVarIndex_1{iselect_1};81 83 VarType=VarTypeCell{iselect}; 82 84 VarType_1=VarTypeCell_1{iselect_1}; … … 85 87 testU=~isempty(VarType.vector_x)&& ~isempty(VarType.vector_y);%vector field 86 88 testU_1=~isempty(VarType_1.vector_x)&& ~isempty(VarType_1.vector_y);%vector field 87 % testfalse=~isempty(VarType.errorflag);88 89 testfalse_1=~isempty(VarType_1.errorflag); 89 90 ivar_C=[VarType.scalar VarType.image VarType.color VarType.ancillary]; %defines index (indices) for the scalar or ancillary fields … … 101 102 if (testU && testU_1) || (~testU && ~testU_1) 102 103 %check coincidence in positions 103 %unstructured coordinates 104 if testX 104 %unstructured coordinates for the first field 105 if testX 106 XName=Field.ListVarName{VarType.coord_x}; 107 YName=Field.ListVarName{VarType.coord_y}; 108 eval(['vec_X=Field.' XName ';']) 109 eval(['vec_Y=Field.' YName ';']) 110 nbpoints=numel(vec_X); 111 vec_X=reshape(vec_X,nbpoints,1); 112 vec_Y=reshape(vec_Y,nbpoints,1); 113 if testX_1 %unstructured coordinates for the second field 114 X_1_Name=Field_1.ListVarName{VarType_1.coord_x}; 115 Y_1_Name=Field_1.ListVarName{VarType_1.coord_y}; 116 eval(['vec_X_1=Field_1.' X_1_Name ';']) 117 eval(['vec_Y_1=Field_1.' Y_1_Name ';']) 118 119 else %structured coordinates for the second field 120 y_1_Name=Field_1.ListVarName{VarType_1.coord(1)}; 121 x_1_Name=Field_1.ListVarName{VarType_1.coord(2)}; 122 eval(['y_1=Field_1.' y_1_Name ';']) 123 eval(['x_1=Field_1.' x_1_Name ';']) 124 if isequal(numel(x_1),2) 125 x_1=linspace(x_1(1),x_1(2),nbpoints_x_1); 126 end 127 if isequal(numel(y_1),2) 128 y_1=linspace(y_1(1),y_1(2),nbpoints_y_1); 129 end 130 [vec_X_1,vec_Y_1]=meshgrid(x_1,y_1); 131 end 132 vec_X_1=reshape(vec_X_1,[],1); 133 vec_Y_1=reshape(vec_Y_1,[],1); 134 if testfalse_1 135 FFName_1=Field_1.ListVarName{VarType_1.errorflag}; 136 eval(['vec_FF_1=Field_1.' FFName_1 ';']) 137 vec_FF_1=reshape(vec_FF_1,[],1); 138 indsel=find(~vec_FF_1); 139 vec_X_1=vec_X_1(indsel); 140 vec_Y_1=vec_Y_1(indsel); 141 end 105 142 if testU % vector fields 106 143 U_1_Name=Field_1.ListVarName{VarType_1.vector_x}; … … 126 163 end 127 164 end 128 XName=Field.ListVarName{VarType.coord_x}; 129 YName=Field.ListVarName{VarType.coord_y}; 130 eval(['vec_X=Field.' XName ';']) 131 eval(['vec_Y=Field.' YName ';']) 132 nbpoints=numel(vec_X); 133 vec_X=reshape(vec_X,nbpoints,1); 134 vec_Y=reshape(vec_Y,nbpoints,1); 135 if testX_1 %unstructured coordinates for the second field 136 X_1_Name=Field_1.ListVarName{VarType_1.coord_x}; 137 Y_1_Name=Field_1.ListVarName{VarType_1.coord_y}; 138 eval(['vec_X_1=Field_1.' X_1_Name ';']) 139 eval(['vec_Y_1=Field_1.' Y_1_Name ';']) 140 141 else %structured coordinates for the second field 142 y_1_Name=Field_1.ListVarName{VarType_1.coord(1)}; 143 x_1_Name=Field_1.ListVarName{VarType_1.coord(2)}; 144 eval(['y_1=Field_1.' y_1_Name ';']) 145 eval(['x_1=Field_1.' x_1_Name ';']) 146 if isequal(numel(x_1),2) 147 x_1=linspace(x_1(1),x_1(2),nbpoints_x_1); 148 end 149 if isequal(numel(y_1),2) 150 y_1=linspace(y_1(1),y_1(2),nbpoints_y_1); 151 end 152 [vec_X_1,vec_Y_1]=meshgrid(x_1,y_1); 153 end 154 vec_X_1=reshape(vec_X_1,nbpoints_x_1*nbpoints_y_1,1); 155 vec_Y_1=reshape(vec_Y_1,nbpoints_x_1*nbpoints_y_1,1); 156 if testfalse_1 157 FFName_1=Field_1.ListVarName{VarType_1.errorflag}; 158 eval(['vec_FF_1=Field_1.' FFName_1 ';']) 159 vec_FF_1=reshape(vec_FF_1,nbpoints_1,1); 160 indsel=find(~vec_FF_1); 161 vec_X_1=vec_X_1(indsel); 162 vec_Y_1=vec_Y_1(indsel); 163 end 165 164 166 if ~isequal(vec_X_1,vec_X) && ~isequal(vec_Y_1,vec_Y) % if the unstructured positions are not the same 165 167 if testU … … 228 230 if testU && ~testU_1 229 231 AName_1=Field_1.ListVarName{ivar_C_1}; 230 if isfield(Field_1,'VarAttribute') & &numel(Field_1.VarAttribute)>=ivar_C_1232 if isfield(Field_1,'VarAttribute') & numel(Field_1.VarAttribute)>=ivar_C_1 231 233 AAttr=Field_1.VarAttribute{ivar_C_1} ; 232 234 else … … 236 238 XName_1=Field_1.ListVarName{VarType_1.coord_x}; 237 239 YName_1=Field_1.ListVarName{VarType_1.coord_y}; 238 %SubData.ListVarName=[SubData.ListVarName {XName_1} {YName_1}];239 240 DimCell=Field_1.VarDimName([VarType_1.coord_x VarType_1.coord_y ]); 240 241 if isfield(Field_1,'VarAttribute') 241 242 if numel(Field_1.VarAttribute)>=VarType_1.coord_x 242 XAttr=Field_1.VarAttribute{VarType_1.coord_x} ;243 XAttr=Field_1.VarAttribute{VarType_1.coord_x}; 243 244 else 244 245 XAttr=[]; 245 246 end 246 247 if numel(Field_1.VarAttribute)>=VarType_1.coord_y 247 YAttr=Field_1.VarAttribute{VarType_1.coord_y} ;248 YAttr=Field_1.VarAttribute{VarType_1.coord_y}; 248 249 else 249 250 YAttr=[]; … … 361 362 eval(['SubData.' VName_1_1 '=Field_1.' VName_1 ';']) 362 363 end 363 364 364
Note: See TracChangeset
for help on using the changeset viewer.