[201] | 1 | %'plot_field': plot any field with the structure defined in the uvmat package
|
---|
| 2 | %------------------------------------------------------------------------
|
---|
| 3 | %
|
---|
| 4 | % This function is used by uvmat to plot fields. It automatically chooses the representation
|
---|
| 5 | % appropriate to the input field structure:
|
---|
[292] | 6 | % 2D vector fields are represented by arrows, 2D scalar fields by grey scale images or contour plots, 1D fields are represented by usual plot with (abscissa, ordinate).
|
---|
[201] | 7 | % The input field structure is first tested by check_field_structure.m,
|
---|
[512] | 8 | % then split into blocks of related variables by find_field_cells.m.
|
---|
[292] | 9 | % The dimensionality of each block is obtained by this function
|
---|
[201] | 10 | % considering the presence of variables with the attribute .Role='coord_x'
|
---|
| 11 | % and/or coord_y and/or coord_z (case of unstructured coordinates), or
|
---|
| 12 | % dimension variables (case of matrices).
|
---|
| 13 | %
|
---|
[625] | 14 | % function [PlotType,PlotParamOut,haxes]= plot_field(Data,haxes,PlotParam,PosColorbar)
|
---|
[201] | 15 | %
|
---|
[822] | 16 | % OUPUT:
|
---|
[866] | 17 | % PlotType: type of plot: 'text','line'(curve plot),'plane':2D view,'volume', or errormsg
|
---|
[201] | 18 | % PlotParamOut: structure, representing the updated plotting parameters, in case of automatic scaling
|
---|
| 19 | % haxes: handle of the plotting axis, when a new figure is created.
|
---|
| 20 | %
|
---|
[822] | 21 | %INPUT
|
---|
[201] | 22 | % Data: structure describing the field to plot
|
---|
| 23 | % (optional) .ListGlobalAttribute: cell listing the names of the global attributes
|
---|
| 24 | % .Att_1,Att_2... : values of the global attributes
|
---|
| 25 | % (requested) .ListVarName: list of variable names to select (cell array of char strings {'VarName1', 'VarName2',...} )
|
---|
| 26 | % (requested) .VarDimName: list of dimension names for each element of .ListVarName (cell array of string cells)
|
---|
| 27 | % .VarAttribute: cell of attributes for each element of .ListVarName (cell array of structures of the form VarAtt.key=value)
|
---|
| 28 | % (requested) .Var1, .Var2....: variables (Matlab arrays) with names listed in .ListVarName
|
---|
| 29 | %
|
---|
| 30 | % Variable attribute .Role :
|
---|
| 31 | % The only variable attribute used for plotting purpose is .Role which can take
|
---|
| 32 | % the values
|
---|
| 33 | % Role = 'scalar': (default) represents a scalar field
|
---|
| 34 | % = 'coord_x', 'coord_y', 'coord_z': represents a separate set of
|
---|
| 35 | % unstructured coordinate x, y or z
|
---|
| 36 | % = 'vector': represents a vector field whose number of components
|
---|
| 37 | % is given by the last dimension (called 'nb_dim')
|
---|
| 38 | % = 'vector_x', 'vector_y', 'vector_z' :represents the x, y or z component of a vector
|
---|
| 39 | % = 'warnflag' : provides a warning flag about the quality of data in a 'Field', default=0, no warning
|
---|
| 40 | % = 'errorflag': provides an error flag marking false data,
|
---|
| 41 | % default=0, no error. Different non zero values can represent different criteria of elimination.
|
---|
| 42 | %
|
---|
| 43 | % haxes: handle of the plotting axes to update with the new plot. If this input is absent or not a valid axes handle, a new figure is created.
|
---|
| 44 | %
|
---|
[294] | 45 | % PlotParam: structure containing the parameters for plotting, as read on the uvmat or view_field GUI (by function 'read_GUI.m').
|
---|
| 46 | % Contains three substructures:
|
---|
[748] | 47 | % .Axes: coordinate parameters:
|
---|
[294] | 48 | % .CheckFixLimits:=0 (default) adjust axes limit to the X,Y data, =1: preserves the previous axes limits
|
---|
[748] | 49 | % .Axes.CheckFixAspectRatio: =0 (default):automatic adjustment of the graph, keep 1 to 1 aspect ratio for x and y scales.
|
---|
| 50 | % .Axes.AspectRatio: imposed aspect ratio y/x of axis unit plots
|
---|
[201] | 51 | % --scalars--
|
---|
| 52 | % .Scalar.MaxA: upper bound (saturation color) for the scalar representation, max(field) by default
|
---|
| 53 | % .Scalar.MinA: lower bound (saturation) for the scalar representation, min(field) by default
|
---|
[292] | 54 | % .Scalar.CheckFixScal: =0 (default) lower and upper bounds of the scalar representation set to the min and max of the field
|
---|
[201] | 55 | % =1 lower and upper bound imposed by .AMax and .MinA
|
---|
[421] | 56 | % .Scalar.CheckBW= 1: black and white representation imposed, =0 color imposed (color scale or rgb),
|
---|
| 57 | % =[]: automatic (B/W for integer positive scalars, color else)
|
---|
[292] | 58 | % .Scalar.CheckContours= 1: represent scalars by contour plots (Matlab function 'contour'); =0 by default
|
---|
[201] | 59 | % .IncrA : contour interval
|
---|
| 60 | % -- vectors--
|
---|
| 61 | % .Vectors.VecScale: scale for the vector representation
|
---|
[292] | 62 | % .Vectors.CheckFixVec: =0 (default) automatic length for vector representation, =1: length set by .VecScale
|
---|
| 63 | % .Vectors.CheckHideFalse= 0 (default) false vectors represented in magenta, =1: false vectors not represented;
|
---|
| 64 | % .Vectors.CheckHideWarning= 0 (default) vectors marked by warnflag~=0 marked in black, 1: no warning representation;
|
---|
| 65 | % .Vectors.CheckDecimate4 = 0 (default) all vectors reprtesented, =1: half of the vectors represented along each coordinate
|
---|
[201] | 66 | % -- vector color--
|
---|
| 67 | % .Vectors.ColorCode= 'black','white': imposed color (default ='blue')
|
---|
| 68 | % 'rgb', : three colors red, blue, green depending
|
---|
| 69 | % on thresholds .colcode1 and .colcode2 on the input scalar value (C)
|
---|
| 70 | % 'brg': like rgb but reversed color order (blue, green, red)
|
---|
| 71 | % '64 colors': continuous color from blue to red (multijet)
|
---|
| 72 | % .Vectors.colcode1 : first threshold for rgb, first value for'continuous'
|
---|
| 73 | % .Vectors.colcode2 : second threshold for rgb, last value (saturation) for 'continuous'
|
---|
[292] | 74 | % .Vectors.CheckFixedCbounds; =0 (default): the bounds on C representation are min and max, =1: they are fixed by .Minc and .MaxC
|
---|
[201] | 75 | % .Vectors.MinC = imposed minimum of the scalar field used for vector color;
|
---|
| 76 | % .Vectors.MaxC = imposed maximum of the scalar field used for vector color;
|
---|
| 77 | %
|
---|
[546] | 78 | % PosColorbar: % if absent, no action on colorbar
|
---|
| 79 | % % if empty, suppress any existing colorbar
|
---|
| 80 | % % if not empty, display a colorbar for B&W images at position PosColorbar
|
---|
| 81 | % expressed in figure relative unit (ex [0.821 0.471 0.019 0.445])
|
---|
[201] | 82 |
|
---|
[924] | 83 | %=======================================================================
|
---|
[1126] | 84 | % Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
|
---|
[924] | 85 | % http://www.legi.grenoble-inp.fr
|
---|
[1127] | 86 | % Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
|
---|
[924] | 87 | %
|
---|
[201] | 88 | % This file is part of the toolbox UVMAT.
|
---|
[924] | 89 | %
|
---|
[201] | 90 | % UVMAT is free software; you can redistribute it and/or modify
|
---|
[924] | 91 | % it under the terms of the GNU General Public License as published
|
---|
| 92 | % by the Free Software Foundation; either version 2 of the license,
|
---|
| 93 | % or (at your option) any later version.
|
---|
| 94 | %
|
---|
[201] | 95 | % UVMAT is distributed in the hope that it will be useful,
|
---|
| 96 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 97 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
[924] | 98 | % GNU General Public License (see LICENSE.txt) for more details.
|
---|
| 99 | %=======================================================================
|
---|
[201] | 100 |
|
---|
[781] | 101 | function [PlotType,PlotParamOut,haxes]= plot_field(Data,haxes,PlotParam)
|
---|
[247] | 102 |
|
---|
[388] | 103 | %% default input and output
|
---|
[1077] | 104 | if ~exist('PlotParam','var'),PlotParam=[];end
|
---|
[201] | 105 | PlotType='text'; %default
|
---|
[749] | 106 | if ~isfield(PlotParam,'Axes')
|
---|
[748] | 107 | PlotParam.Axes=[];
|
---|
[582] | 108 | if isfield(Data,'CoordUnit')
|
---|
[748] | 109 | PlotParam.Axes.CheckFixAspectRatio=1;
|
---|
| 110 | PlotParam.Axes.AspectRatio=1; %set axes equal by default if CoordUnit is defined
|
---|
[582] | 111 | end
|
---|
[292] | 112 | end
|
---|
[569] | 113 | PlotParamOut=PlotParam;%default
|
---|
[201] | 114 |
|
---|
[388] | 115 | %% check input structure
|
---|
[1098] | 116 | [CellInfo,NbDimArray,errormsg]=find_field_cells(Data);
|
---|
| 117 | if ~isempty(errormsg)
|
---|
| 118 | msgbox_uvmat('ERROR',['input of plot_field/find_field_cells: ' errormsg]);
|
---|
| 119 | return
|
---|
| 120 | end
|
---|
| 121 | index_0D=find(NbDimArray==0);
|
---|
| 122 | index_1D=find(NbDimArray==1);
|
---|
| 123 | index_2D=find(NbDimArray==2);%find 2D fields
|
---|
| 124 | index_3D=find(NbDimArray>2,1);
|
---|
| 125 | if ~isempty(index_3D)
|
---|
| 126 | msgbox_uvmat('ERROR','volume plot not implemented yet');
|
---|
| 127 | return
|
---|
| 128 | end
|
---|
[294] | 129 |
|
---|
[388] | 130 | %% test axes and figure
|
---|
[429] | 131 | testnewfig=1;%test to create a new figure (default)
|
---|
| 132 | testzoomaxes=0;%test for the existence of a zoom secondary figure attached to the plotting axes
|
---|
| 133 | if exist('haxes','var')
|
---|
| 134 | if ishandle(haxes)
|
---|
| 135 | if isequal(get(haxes,'Type'),'axes')
|
---|
| 136 | testnewfig=0;
|
---|
| 137 | AxeData=get(haxes,'UserData');
|
---|
| 138 | if isfield(AxeData,'ZoomAxes')&& ishandle(AxeData.ZoomAxes)
|
---|
| 139 | if isequal(get(AxeData.ZoomAxes,'Type'),'axes')
|
---|
| 140 | testzoomaxes=1;
|
---|
| 141 | zoomaxes=AxeData.ZoomAxes;
|
---|
[388] | 142 | end
|
---|
| 143 | end
|
---|
| 144 | end
|
---|
[201] | 145 | end
|
---|
[429] | 146 | end
|
---|
| 147 |
|
---|
| 148 | %% create a new figure and axes if the plotting axes does not exist
|
---|
| 149 | if testnewfig
|
---|
| 150 | hfig=figure;
|
---|
| 151 | set(hfig,'Units','normalized')
|
---|
| 152 | haxes=axes;
|
---|
| 153 | set(haxes,'position',[0.13,0.2,0.775,0.73])
|
---|
[569] | 154 | PlotParamOut.NextPlot='add'; %parameter for plot_profile
|
---|
[429] | 155 | else
|
---|
| 156 | hfig=get(haxes,'parent');
|
---|
| 157 | set(0,'CurrentFigure',hfig)% the parent of haxes becomes the current figure
|
---|
| 158 | set(hfig,'CurrentAxes',haxes)% haxes becomes the current axes of the parent figure
|
---|
| 159 | end
|
---|
| 160 |
|
---|
| 161 | %% set axes properties
|
---|
[748] | 162 | if isfield(PlotParamOut.Axes,'CheckFixLimits') && isequal(PlotParamOut.Axes.CheckFixLimits,1) %adjust the graph limits
|
---|
[429] | 163 | set(haxes,'XLimMode', 'manual')
|
---|
| 164 | set(haxes,'YLimMode', 'manual')
|
---|
| 165 | else
|
---|
| 166 | set(haxes,'XLimMode', 'auto')
|
---|
| 167 | set(haxes,'YLimMode', 'auto')
|
---|
| 168 | end
|
---|
[760] | 169 |
|
---|
| 170 | if isfield(PlotParamOut.Axes,'CheckFixAspectRatio') && isequal(PlotParamOut.Axes.CheckFixAspectRatio,1)&&isfield(PlotParamOut.Axes,'AspectRatio')
|
---|
| 171 | set(haxes,'DataAspectRatioMode','manual')
|
---|
| 172 | set(haxes,'DataAspectRatio',[PlotParamOut.Axes.AspectRatio 1 1])
|
---|
| 173 | else
|
---|
| 174 | set(haxes,'DataAspectRatioMode','auto')%automatic aspect ratio
|
---|
| 175 | end
|
---|
| 176 |
|
---|
[429] | 177 | errormsg='';
|
---|
| 178 | AxeData=get(haxes,'UserData');
|
---|
| 179 |
|
---|
| 180 | %% 2D plots
|
---|
| 181 | if isempty(index_2D)
|
---|
[781] | 182 | plot_plane([],[],haxes,[]);%removes images or vector plots in the absence of 2D field plot
|
---|
[429] | 183 | else %plot 2D field
|
---|
[781] | 184 | % if ~exist('PosColorbar','var'),PosColorbar=[];end;
|
---|
| 185 | [tild,PlotParamOut,PlotType,errormsg]=plot_plane(Data,CellInfo(index_2D),haxes,PlotParamOut);
|
---|
[429] | 186 | AxeData.NbDim=2;
|
---|
| 187 | if testzoomaxes && isempty(errormsg)
|
---|
[781] | 188 | [zoomaxes,PlotParamOut,tild,errormsg]=plot_plane(Data,CellInfo(index_2D),zoomaxes,PlotParamOut);
|
---|
[429] | 189 | AxeData.ZoomAxes=zoomaxes;
|
---|
[201] | 190 | end
|
---|
[429] | 191 | end
|
---|
| 192 |
|
---|
| 193 | %% 1D plot (usual graph y vs x)
|
---|
[1031] | 194 | if isempty(index_1D)|| ~isempty(index_2D)
|
---|
[429] | 195 | if ~isempty(haxes)
|
---|
[530] | 196 | plot_profile([],[],haxes);%removes usual praphs y vs x in the absence of 1D field plot
|
---|
[201] | 197 | end
|
---|
[429] | 198 | else %plot 1D field (usual graph y vs x)
|
---|
[644] | 199 | CheckHold=0;
|
---|
| 200 | if isfield(PlotParam,'CheckHold')
|
---|
| 201 | CheckHold= PlotParam.CheckHold;
|
---|
| 202 | end
|
---|
[874] | 203 | PlotParamOut=plot_profile(Data,CellInfo(index_1D),haxes,PlotParamOut,CheckHold);%
|
---|
[872] | 204 | if isempty(index_2D)
|
---|
| 205 | if isfield(PlotParamOut,'Vectors')
|
---|
| 206 | PlotParamOut=rmfield(PlotParamOut,'Vectors');
|
---|
| 207 | end
|
---|
| 208 | if isfield(PlotParamOut,'Scalar')
|
---|
| 209 | PlotParamOut=rmfield(PlotParamOut,'Scalar');
|
---|
| 210 | end
|
---|
[871] | 211 | end
|
---|
[429] | 212 | if testzoomaxes
|
---|
[748] | 213 | [zoomaxes,PlotParamOut.Axes]=plot_profile(Data,CellInfo(index_1D),zoomaxes,PlotParamOut.Axes,CheckHold);
|
---|
[429] | 214 | AxeData.ZoomAxes=zoomaxes;
|
---|
[201] | 215 | end
|
---|
[429] | 216 | PlotType='line';
|
---|
| 217 | end
|
---|
| 218 |
|
---|
[760] | 219 | %% aspect ratio
|
---|
| 220 | AspectRatio=get(haxes,'DataAspectRatio');
|
---|
| 221 | PlotParamOut.Axes.AspectRatio=AspectRatio(1)/AspectRatio(2);
|
---|
| 222 |
|
---|
[429] | 223 | %% text display
|
---|
[873] | 224 | if ~(isfield(PlotParamOut,'Axes')&&isfield(PlotParamOut.Axes,'TextDisplay')&&(PlotParamOut.Axes.TextDisplay)) % if text is not already given as statistics
|
---|
| 225 | htext=findobj(hfig,'Tag','TableDisplay');
|
---|
[874] | 226 | if ~isempty(htext)%&&~isempty(hchecktable)
|
---|
[873] | 227 | if isempty(index_0D)
|
---|
[434] | 228 | else
|
---|
[873] | 229 | errormsg=plot_text(Data,CellInfo(index_0D),htext);
|
---|
| 230 | set(htext,'visible','on')
|
---|
[434] | 231 | end
|
---|
[873] | 232 | set(hfig,'Unit','pixels');
|
---|
| 233 | set(htext,'Unit','pixels')
|
---|
| 234 | PosFig=get(hfig,'Position');
|
---|
| 235 | % case of no plot with view_field: only text display
|
---|
| 236 | if strcmp(get(hfig,'Tag'),'view_field')
|
---|
| 237 | if isempty(index_1D) && isempty(index_2D)% case of no plot: only text display
|
---|
| 238 | set(haxes,'Visible','off')
|
---|
| 239 | PosTable=get(htext,'Position');
|
---|
| 240 | set(hfig,'Position',[PosFig(1) PosFig(2) PosTable(3) PosTable(4)])
|
---|
| 241 | else
|
---|
| 242 | set(haxes,'Visible','on')
|
---|
| 243 | set(hfig,'Position',[PosFig(1) PosFig(2) 877 677])%default size for view_field
|
---|
| 244 | end
|
---|
| 245 | end
|
---|
[294] | 246 | end
|
---|
[201] | 247 | end
|
---|
[388] | 248 | %% display error message
|
---|
[201] | 249 | if ~isempty(errormsg)
|
---|
[866] | 250 | PlotType=errormsg;
|
---|
[201] | 251 | msgbox_uvmat('ERROR', errormsg)
|
---|
| 252 | end
|
---|
| 253 |
|
---|
| 254 | %% update the parameters stored in AxeData
|
---|
[429] | 255 | if ishandle(haxes)&&( ~isempty(index_2D)|| ~isempty(index_1D))
|
---|
[388] | 256 | if isfield(PlotParamOut,'MinX')
|
---|
[569] | 257 | AxeData.RangeX=[PlotParamOut.MinX PlotParamOut.MaxX];
|
---|
| 258 | AxeData.RangeY=[PlotParamOut.MinY PlotParamOut.MaxY];
|
---|
[388] | 259 | end
|
---|
| 260 | set(haxes,'UserData',AxeData)
|
---|
| 261 | end
|
---|
[201] | 262 |
|
---|
[206] | 263 | %% update the plotted field stored in parent figure
|
---|
[429] | 264 | if ~isempty(index_2D)|| ~isempty(index_1D)
|
---|
| 265 | FigData=get(hfig,'UserData');
|
---|
[511] | 266 | if strcmp(get(hfig,'tag'),'view_field')||strcmp(get(hfig,'tag'),'uvmat')
|
---|
[1097] | 267 | if ~isempty(get(haxes,'tag'))
|
---|
[511] | 268 | FigData.(get(haxes,'tag'))=Data;
|
---|
[1097] | 269 | end
|
---|
[429] | 270 | set(hfig,'UserData',FigData)
|
---|
| 271 | end
|
---|
[388] | 272 | end
|
---|
[292] | 273 |
|
---|
[201] | 274 | %-------------------------------------------------------------------
|
---|
[690] | 275 | % --- plot 0D fields: display data values without plot
|
---|
| 276 | %------------------------------------------------------------------
|
---|
[530] | 277 | function errormsg=plot_text(FieldData,CellInfo,htext)
|
---|
[690] | 278 |
|
---|
[581] | 279 | errormsg='';
|
---|
[201] | 280 | txt_cell={};
|
---|
[429] | 281 | Data={};
|
---|
[690] | 282 | VarIndex=[];
|
---|
[530] | 283 | for icell=1:length(CellInfo)
|
---|
[535] | 284 |
|
---|
| 285 | % select types of variables to be projected
|
---|
| 286 | ListProj={'VarIndex_scalar','VarIndex_image','VarIndex_color','VarIndex_vector_x','VarIndex_vector_y'};
|
---|
| 287 | check_proj=false(size(FieldData.ListVarName));
|
---|
| 288 | for ilist=1:numel(ListProj)
|
---|
| 289 | if isfield(CellInfo{icell},ListProj{ilist})
|
---|
| 290 | check_proj(CellInfo{icell}.(ListProj{ilist}))=1;
|
---|
| 291 | end
|
---|
| 292 | end
|
---|
[690] | 293 | VarIndex=[VarIndex find(check_proj)];
|
---|
| 294 | end
|
---|
| 295 |
|
---|
| 296 | % data need to be displayed in a table
|
---|
[881] | 297 | % if strcmp(get(htext,'Type'),'uitable')% display data in a table
|
---|
| 298 | % VarNameCell=cell(1,numel(VarIndex));% prepare list of variable names to display (titles of columns)
|
---|
| 299 | % VarLength=zeros(1,numel(VarIndex)); % default number of values for each variable
|
---|
| 300 | % for ivar=1:numel(VarIndex)
|
---|
| 301 | % VarNameCell{ivar}=FieldData.ListVarName{VarIndex(ivar)};
|
---|
| 302 | % VarLength(ivar)=numel(FieldData.(VarNameCell{ivar}));
|
---|
| 303 | % end
|
---|
| 304 | % set(htext,'ColumnName',VarNameCell)
|
---|
| 305 | % Data=cell(max(VarLength),numel(VarIndex));% prepare the table of data display
|
---|
| 306 | %
|
---|
| 307 | % for ivar=1:numel(VarIndex)
|
---|
| 308 | % VarValue=FieldData.(VarNameCell{ivar});
|
---|
| 309 | % VarValue=reshape(VarValue,[],1);% reshape values array in a column
|
---|
| 310 | % Data(1:numel(VarValue),ivar)=num2cell(VarValue);
|
---|
| 311 | % end
|
---|
| 312 | % set(htext,'Data',Data)
|
---|
| 313 | % end
|
---|
[690] | 314 | % if numel(VarValue)>1 && numel(VarValue)<10 % case of a variable with several values
|
---|
| 315 | % for ind=1:numel(VarValue)
|
---|
| 316 | % VarNameCell{1,ind}=[VarName '_' num2str(ind)];% indicate each value by an index
|
---|
| 317 | % end
|
---|
| 318 | % else
|
---|
| 319 | % VarNameCell={VarName};
|
---|
| 320 | % end
|
---|
| 321 | % if numel(VarValue)<10
|
---|
| 322 | % if isempty(VarValue)
|
---|
| 323 | % VarValueCell={'[]'};
|
---|
| 324 | % else
|
---|
| 325 | % VarValueCell=num2cell(VarValue);
|
---|
| 326 | % end
|
---|
| 327 | % if isempty(Data)
|
---|
| 328 | % Data =[VarNameCell VarValueCell];
|
---|
| 329 | % else
|
---|
| 330 | % Data =[Data [VarNameCell VarValueCell]];
|
---|
| 331 | % end
|
---|
| 332 | % else
|
---|
| 333 | % if isempty(Data)
|
---|
| 334 | % Data =[VarNameCell; num2cell(VarValue)];
|
---|
| 335 | % else
|
---|
| 336 | % Data =[Data [VarNameCell; {['size ' num2str(size(VarValue))]}]];
|
---|
| 337 | % end
|
---|
| 338 | % end
|
---|
| 339 | % if size(VarValue,1)==1
|
---|
| 340 | % txt=[VarName '=' num2str(VarValue)];
|
---|
| 341 | % txt_cell=[txt_cell;{txt}];
|
---|
| 342 | % end
|
---|
| 343 | % end
|
---|
| 344 | % end
|
---|
| 345 | % if strcmp(get(htext,'Type'),'uitable')% display data in a table
|
---|
| 346 | %
|
---|
| 347 | %
|
---|
| 348 | % set(htext,'Data',Data(2:end,:))
|
---|
| 349 | % else % display in a text edit box
|
---|
| 350 | % set(htext,'String',txt_cell)
|
---|
| 351 | % set(htext,'UserData',txt_cell)% for temporary storage when the edit box is used for mouse display
|
---|
| 352 | % end
|
---|
[201] | 353 |
|
---|
[429] | 354 |
|
---|
[201] | 355 | %-------------------------------------------------------------------
|
---|
[690] | 356 | % --- plot 1D fields (usual x,y plots)
|
---|
| 357 | %-------------------------------------------------------------------
|
---|
[1077] | 358 | %INPUT
|
---|
| 359 | % Data: structure describing the field to plot
|
---|
| 360 | % (optional) .ListGlobalAttribute: cell listing the names of the global attributes
|
---|
| 361 | % .Att_1,Att_2... : values of the global attributes
|
---|
| 362 | % (requested) .ListVarName: list of variable names to select (cell array of char strings {'VarName1', 'VarName2',...} )
|
---|
| 363 | % (requested) .VarDimName: list of dimension names for each element of .ListVarName (cell array of string cells)
|
---|
| 364 | % .VarAttribute: cell of attributes for each element of .ListVarName (cell array of structures of the form VarAtt.key=value)
|
---|
| 365 | % (requested) .Var1, .Var2....: variables (Matlab arrays) with names listed in .ListVarName
|
---|
| 366 | %
|
---|
| 367 | % Variable attribute .Role :
|
---|
| 368 | % The only variable attribute used for plotting purpose is .Role which can take
|
---|
| 369 | % the values:
|
---|
| 370 | % Role = 'coord_x' or 'histo' to label the x coordinate
|
---|
| 371 | % ='coord_y' or 'discrete' to label the y coordinate, variables labelled as 'discrete'
|
---|
| 372 | % will be plotted as isolated points while variables labelled as 'coord_y' will be plotted as continuous lines
|
---|
| 373 | % other variables will not be taken into account for plot_profile
|
---|
[201] | 374 |
|
---|
[1077] | 375 | function PlotParamOut=plot_profile(Data,CellInfo,haxes,PlotParam,CheckHold)
|
---|
| 376 |
|
---|
[644] | 377 | %% initialization
|
---|
[874] | 378 | if ~(exist('PlotParam','var')&&~isempty(PlotParam.Axes))
|
---|
[292] | 379 | Coordinates=[];
|
---|
[874] | 380 | PlotParamOut.Axes=Coordinates;
|
---|
| 381 | else
|
---|
| 382 | Coordinates=PlotParam.Axes;
|
---|
| 383 | PlotParamOut=PlotParam;
|
---|
[201] | 384 | end
|
---|
| 385 | hfig=get(haxes,'parent');
|
---|
[644] | 386 | legend_str={};
|
---|
| 387 |
|
---|
[1077] | 388 | %% suppress existing plot if empty Data
|
---|
| 389 | if isempty(Data)
|
---|
[201] | 390 | hplot=findobj(haxes,'tag','plot_line');
|
---|
| 391 | if ~isempty(hplot)
|
---|
| 392 | delete(hplot)
|
---|
| 393 | end
|
---|
| 394 | hlegend=findobj(hfig,'tag','legend');
|
---|
| 395 | if ~isempty(hlegend)
|
---|
| 396 | delete(hlegend)
|
---|
| 397 | end
|
---|
| 398 | return
|
---|
| 399 | end
|
---|
| 400 |
|
---|
[644] | 401 | %% set the colors of the successive plots (designed to produce rgb for the three components of color images)
|
---|
[651] | 402 | ColorOrder=[1 0 0;0 1 0;0 0 1;0 0.75 0.75;0.75 0 0.75;0.75 0.75 0;0.25 0.25 0.25];
|
---|
| 403 | set(hfig,'DefaultAxesColorOrder',ColorOrder)
|
---|
[644] | 404 | if CheckHold
|
---|
[690] | 405 | set(haxes,'NextPlot','add')
|
---|
[644] | 406 | else
|
---|
| 407 | set(haxes,'NextPlot','replace')
|
---|
[201] | 408 | end
|
---|
| 409 |
|
---|
| 410 | %% prepare the string for plot command
|
---|
| 411 | plotstr='hhh=plot(';
|
---|
| 412 | xtitle='';
|
---|
| 413 | ytitle='';
|
---|
[644] | 414 | test_newplot=~CheckHold;
|
---|
[569] | 415 | MinX=[];
|
---|
| 416 | MaxX=[];
|
---|
| 417 | MinY_cell=[];
|
---|
| 418 | MaxY_cell=[];
|
---|
[1077] | 419 | testplot=ones(size(Data.ListVarName));%default test for plotted variables
|
---|
[201] | 420 | %loop on input fields
|
---|
[530] | 421 | for icell=1:numel(CellInfo)
|
---|
[1077] | 422 | VarIndex=[CellInfo{icell}.YIndex CellInfo{icell}.YIndex_discrete];% indices of the selected variables in the list Data.ListVarName
|
---|
[1045] | 423 | coord_x_index=CellInfo{icell}.XIndex;
|
---|
[1077] | 424 | coord_x_name{icell}=Data.ListVarName{coord_x_index};
|
---|
| 425 | coord_x{icell}=Data.(Data.ListVarName{coord_x_index});%coordinate variable set as coord_x
|
---|
[569] | 426 | if isempty(find(strcmp(coord_x_name{icell},coord_x_name(1:end-1)), 1)) %xtitle not already selected
|
---|
[426] | 427 | xtitle=[xtitle coord_x_name{icell}];
|
---|
[1077] | 428 | if isfield(Data,'VarAttribute')&& numel(Data.VarAttribute)>=coord_x_index && isfield(Data.VarAttribute{coord_x_index},'units')
|
---|
| 429 | xtitle=[xtitle '(' Data.VarAttribute{coord_x_index}.units '), '];
|
---|
[426] | 430 | else
|
---|
| 431 | xtitle=[xtitle ', '];
|
---|
| 432 | end
|
---|
[201] | 433 | end
|
---|
[729] | 434 | if ~isempty(coord_x{icell})
|
---|
| 435 | MinX(icell)=min(coord_x{icell});
|
---|
| 436 | MaxX(icell)=max(coord_x{icell});
|
---|
| 437 | testplot(coord_x_index)=0;
|
---|
| 438 | if isfield(CellInfo{icell},'VarIndex_ancillary')
|
---|
| 439 | testplot(CellInfo{icell}.VarIndex_ancillary)=0;
|
---|
| 440 | end
|
---|
| 441 | if isfield(CellInfo{icell},'VarIndex_warnflag')
|
---|
| 442 | testplot(CellInfo{icell}.VarIndex_warnflag)=0;
|
---|
| 443 | end
|
---|
[1077] | 444 | if isfield(Data,'VarAttribute')
|
---|
| 445 | VarAttribute=Data.VarAttribute;
|
---|
[729] | 446 | for ivar=1:length(VarIndex)
|
---|
| 447 | if length(VarAttribute)>=VarIndex(ivar) && isfield(VarAttribute{VarIndex(ivar)},'long_name')
|
---|
| 448 | plotname{VarIndex(ivar)}=VarAttribute{VarIndex(ivar)}.long_name;
|
---|
| 449 | else
|
---|
[1077] | 450 | plotname{VarIndex(ivar)}=Data.ListVarName{VarIndex(ivar)};%name for display in plot A METTRE
|
---|
[729] | 451 | end
|
---|
[201] | 452 | end
|
---|
| 453 | end
|
---|
[1048] | 454 | if isfield(CellInfo{icell},'YIndex_discrete')&& ~isempty(CellInfo{icell}.YIndex_discrete)
|
---|
[729] | 455 | charplot_0='''+''';
|
---|
| 456 | else
|
---|
| 457 | charplot_0='''-''';
|
---|
| 458 | end
|
---|
| 459 | MinY=[];
|
---|
| 460 | MaxY=[];%default
|
---|
| 461 |
|
---|
| 462 | nbplot=0;
|
---|
| 463 | for ivar=1:length(VarIndex)
|
---|
| 464 | if testplot(VarIndex(ivar))
|
---|
[1077] | 465 | VarName=Data.ListVarName{VarIndex(ivar)};
|
---|
[729] | 466 | nbplot=nbplot+1;
|
---|
| 467 | ytitle=[ytitle VarName];
|
---|
[1077] | 468 | if isfield(Data,'VarAttribute')&& numel(Data.VarAttribute)>=VarIndex(ivar) && isfield(Data.VarAttribute{VarIndex(ivar)},'units')
|
---|
| 469 | ytitle=[ytitle '(' Data.VarAttribute{VarIndex(ivar)}.units '), '];
|
---|
[729] | 470 | else
|
---|
| 471 | ytitle=[ytitle ', '];
|
---|
| 472 | end
|
---|
[1077] | 473 | eval(['Data.' VarName '=squeeze(Data.' VarName ');'])
|
---|
| 474 | MinY(ivar)=min(min(Data.(VarName)));
|
---|
| 475 | MaxY(ivar)=max(max(Data.(VarName)));
|
---|
| 476 | plotstr=[plotstr 'coord_x{' num2str(icell) '},Data.' VarName ',' charplot_0 ','];
|
---|
| 477 | eval(['nbcomponent2=size(Data.' VarName ',2);']);
|
---|
| 478 | eval(['nbcomponent1=size(Data.' VarName ',1);']);
|
---|
[729] | 479 | if numel(coord_x{icell})==2
|
---|
| 480 | coord_x{icell}=linspace(coord_x{icell}(1),coord_x{icell}(2),nbcomponent1);
|
---|
| 481 | end
|
---|
| 482 | if nbcomponent1==1|| nbcomponent2==1
|
---|
| 483 | legend_str=[legend_str {VarName}]; %variable with one component
|
---|
| 484 | else %variable with severals components
|
---|
| 485 | for ic=1:min(nbcomponent1,nbcomponent2)
|
---|
| 486 | legend_str=[legend_str [VarName '_' num2str(ic)]]; %variable with severals components
|
---|
| 487 | end % labeled by their index (e.g. color component)
|
---|
| 488 | end
|
---|
[201] | 489 | end
|
---|
| 490 | end
|
---|
[729] | 491 | if ~isempty(MinY)
|
---|
| 492 | MinY_cell(icell)=min(MinY);
|
---|
| 493 | MaxY_cell(icell)=max(MaxY);
|
---|
| 494 | end
|
---|
[201] | 495 | end
|
---|
| 496 | end
|
---|
| 497 |
|
---|
| 498 | %% activate the plot
|
---|
[644] | 499 | if ~isequal(plotstr,'hhh=plot(')
|
---|
[201] | 500 | set(hfig,'CurrentAxes',haxes)
|
---|
| 501 | tag=get(haxes,'tag');
|
---|
| 502 | %%%
|
---|
| 503 | plotstr=[plotstr '''tag'',''plot_line'');'];
|
---|
| 504 | eval(plotstr) %execute plot (instruction plotstr)
|
---|
| 505 | %%%
|
---|
[651] | 506 | set(haxes,'tag',tag)% restitute the axes tag (removed by the command plot)
|
---|
| 507 | set(haxes,'ColorOrder',ColorOrder)% restitute the plot color order (to get red green blue for histograms or cuts of color images)
|
---|
[201] | 508 | grid(haxes, 'on')
|
---|
| 509 | hxlabel=xlabel(xtitle(1:end-2));% xlabel (removes ', ' at the end)
|
---|
| 510 | set(hxlabel,'Interpreter','none')% desable tex interpreter
|
---|
| 511 | if length(legend_str)>=1
|
---|
| 512 | hylabel=ylabel(ytitle(1:end-2));% ylabel (removes ', ' at the end)
|
---|
| 513 | set(hylabel,'Interpreter','none')% desable tex interpreter
|
---|
| 514 | end
|
---|
| 515 | if ~isempty(legend_str)
|
---|
| 516 | hlegend=findobj(hfig,'Tag','legend');
|
---|
| 517 | if isempty(hlegend)
|
---|
| 518 | hlegend=legend(legend_str);
|
---|
| 519 | txt=ver('MATLAB');
|
---|
| 520 | Release=txt.Release;
|
---|
| 521 | relnumb=str2double(Release(3:4));% should be changed to Version for better compatibility
|
---|
| 522 | if relnumb >= 14
|
---|
| 523 | set(hlegend,'Interpreter','none')% desable tex interpreter
|
---|
| 524 | end
|
---|
| 525 | else
|
---|
| 526 | legend_old=get(hlegend,'String');
|
---|
| 527 | if isequal(size(legend_old,1),size(legend_str,1))&&~isequal(legend_old,legend_str)
|
---|
| 528 | set(hlegend,'String',[legend_old legend_str]);
|
---|
| 529 | end
|
---|
| 530 | end
|
---|
| 531 | end
|
---|
| 532 | title_str='';
|
---|
[1077] | 533 | if isfield(Data,'filename')
|
---|
| 534 | [Path, title_str, ext]=fileparts(Data.filename);
|
---|
[201] | 535 | title_str=[title_str ext];
|
---|
| 536 | end
|
---|
[1077] | 537 | if isfield(Data,'Action')&&isfield(Data.Action,'ActionName')
|
---|
[201] | 538 | if ~isequal(title_str,'')
|
---|
| 539 | title_str=[title_str ', '];
|
---|
| 540 | end
|
---|
[1077] | 541 | title_str=[title_str Data.Action.ActionName];
|
---|
[201] | 542 | end
|
---|
| 543 | htitle=title(title_str);
|
---|
[428] | 544 | set(htitle,'Interpreter','none')% desable tex interpreter
|
---|
[201] | 545 | end
|
---|
| 546 |
|
---|
| 547 | %% determine axes bounds
|
---|
[294] | 548 | fix_lim=isfield(Coordinates,'CheckFixLimits') && Coordinates.CheckFixLimits;
|
---|
[569] | 549 | check_lim=isfield(Coordinates,'MinX')&&isfield(Coordinates,'MaxX')&&isfield(Coordinates,'MinY')&&isfield(Coordinates,'MaxY');
|
---|
[201] | 550 | if fix_lim
|
---|
[569] | 551 | if ~check_lim
|
---|
| 552 | fix_lim=0; %free limits if limits are not set,
|
---|
[221] | 553 | end
|
---|
[201] | 554 | end
|
---|
[294] | 555 | if fix_lim
|
---|
| 556 | set(haxes,'XLim',[Coordinates.MinX Coordinates.MaxX])
|
---|
| 557 | set(haxes,'YLim',[Coordinates.MinY Coordinates.MaxY])
|
---|
[569] | 558 | else
|
---|
| 559 | if ~isempty(MinX)
|
---|
| 560 | if check_lim
|
---|
[874] | 561 | Coordinates.MinX=min(min(MinX),Coordinates.MinX);
|
---|
| 562 | Coordinates.MaxX=max(max(MaxX),Coordinates.MaxX);
|
---|
[569] | 563 | else
|
---|
[874] | 564 | Coordinates.MinX=min(MinX);
|
---|
| 565 | Coordinates.MaxX=max(MaxX);
|
---|
[569] | 566 | end
|
---|
| 567 | end
|
---|
| 568 | if ~isempty(MinY_cell)
|
---|
| 569 | if check_lim
|
---|
[874] | 570 | Coordinates.MinY=min(min(MinY_cell),Coordinates.MinY);
|
---|
| 571 | Coordinates.MaxY=max(max(MaxY_cell),Coordinates.MaxY);
|
---|
[569] | 572 | else
|
---|
[874] | 573 | Coordinates.MinY=min(MinY_cell);
|
---|
| 574 | Coordinates.MaxY=max(MaxY_cell);
|
---|
[569] | 575 | end
|
---|
| 576 | end
|
---|
[201] | 577 | end
|
---|
| 578 |
|
---|
[428] | 579 | %% determine plot aspect ratio
|
---|
[789] | 580 | if isfield(Coordinates,'CheckFixAspectRatio') && isequal(Coordinates.CheckFixAspectRatio,1)&&isfield(Coordinates,'AspectRatio')
|
---|
| 581 | set(haxes,'DataAspectRatioMode','manual')
|
---|
| 582 | set(haxes,'DataAspectRatio',[Coordinates.AspectRatio 1 1])
|
---|
| 583 | else
|
---|
| 584 | set(haxes,'DataAspectRatioMode','auto')%automatic aspect ratio
|
---|
| 585 | AspectRatio=get(haxes,'DataAspectRatio');
|
---|
[874] | 586 | Coordinates.AspectRatio=AspectRatio(1)/AspectRatio(2);
|
---|
[789] | 587 | end
|
---|
[874] | 588 | PlotParamOut.Axes= Coordinates;
|
---|
[428] | 589 |
|
---|
[871] | 590 | %% give statistics for pdf
|
---|
[880] | 591 | %ind_var=find(testplot);
|
---|
[881] | 592 | TableData={'Variable';'SampleNbr';'bin size';'Mean';'RMS';'Skewness';'Kurtosis';...
|
---|
[873] | 593 | 'Min';'FirstCentile';'FirstDecile';'Median';'LastDecile';'LastCentile';'Max'};
|
---|
[880] | 594 |
|
---|
[874] | 595 | TextDisplay=0;
|
---|
[873] | 596 | for icell=1:numel(CellInfo)
|
---|
[1058] | 597 | if isfield(CellInfo{icell},'VarIndex_histo')% case of histogram plot
|
---|
[874] | 598 | TextDisplay=1;
|
---|
[1077] | 599 | VarName=Data.ListVarName{CellInfo{icell}.CoordIndex};
|
---|
| 600 | pdf_val=Data.(Data.ListVarName{CellInfo{icell}.VarIndex_histo});
|
---|
[873] | 601 | x=coord_x{icell};
|
---|
[881] | 602 | if isrow(x)
|
---|
| 603 | x=x';
|
---|
| 604 | end
|
---|
| 605 | if ~isequal(size(x,1),size(pdf_val,1))
|
---|
| 606 | pdf_val=pdf_val';
|
---|
| 607 | end
|
---|
| 608 | Val=pdf2stat(x,pdf_val);
|
---|
| 609 | Column=mat2cell(Val,ones(13,1),ones(1,size(Val,2)));
|
---|
| 610 | if size(Val,2)==1%single component
|
---|
| 611 | TitleBar={VarName};
|
---|
| 612 | else
|
---|
| 613 | TitleBar=cell(1,size(Val,2));
|
---|
| 614 | for icomp=1:size(Val,2)
|
---|
| 615 | TitleBar{icomp}=[VarName '_' num2str(icomp)];
|
---|
| 616 | end
|
---|
| 617 | end
|
---|
| 618 | Column=[TitleBar;Column];
|
---|
[873] | 619 | TableData=[TableData Column];
|
---|
| 620 | end
|
---|
| 621 | end
|
---|
[1077] | 622 | if TextDisplay
|
---|
[873] | 623 | disp(TableData);
|
---|
[874] | 624 | PlotParamOut.TableDisplay=TableData;
|
---|
| 625 | else
|
---|
| 626 | if isfield(PlotParamOut,'TableDisplay')
|
---|
| 627 | PlotParamOut=rmfield(PlotParamOut,'TableDisplay');
|
---|
| 628 | end
|
---|
[871] | 629 | end
|
---|
| 630 |
|
---|
[201] | 631 | %-------------------------------------------------------------------
|
---|
[781] | 632 | function [haxes,PlotParamOut,PlotType,errormsg]=plot_plane(Data,CellInfo,haxes,PlotParam)
|
---|
[201] | 633 | %-------------------------------------------------------------------
|
---|
[674] | 634 | PlotType='plane';
|
---|
| 635 | grid(haxes, 'off')% remove grid (possibly remaining from other graphs)
|
---|
[411] | 636 |
|
---|
[201] | 637 | %default plotting parameters
|
---|
| 638 | if ~isfield(PlotParam,'Scalar')
|
---|
| 639 | PlotParam.Scalar=[];
|
---|
| 640 | end
|
---|
| 641 | if ~isfield(PlotParam,'Vectors')
|
---|
| 642 | PlotParam.Vectors=[];
|
---|
| 643 | end
|
---|
[674] | 644 | PlotParamOut=PlotParam;%default
|
---|
| 645 | errormsg='';%default
|
---|
[201] | 646 |
|
---|
[674] | 647 | hfig=get(haxes,'parent');%handle of the figure containing the plot axes
|
---|
[781] | 648 | PosColorbar=[];
|
---|
| 649 | FigData=get(hfig,'UserData');
|
---|
| 650 | if isfield(FigData,'PosColorbar')
|
---|
| 651 | PosColorbar=FigData.PosColorbar;
|
---|
| 652 | end
|
---|
[201] | 653 | hcol=findobj(hfig,'Tag','Colorbar'); %look for colorbar axes
|
---|
| 654 | hima=findobj(haxes,'Tag','ima');% search existing image in the current axes
|
---|
| 655 | test_ima=0; %default: test for image or map plot
|
---|
| 656 | test_vec=0; %default: test for vector plots
|
---|
| 657 | test_black=0;
|
---|
| 658 | test_false=0;
|
---|
| 659 | test_C=0;
|
---|
| 660 | XName='';
|
---|
| 661 | x_units='';
|
---|
| 662 | YName='';
|
---|
| 663 | y_units='';
|
---|
[674] | 664 |
|
---|
| 665 | % loop on the input field cells
|
---|
[1031] | 666 | for icell=1:numel(CellInfo)
|
---|
[530] | 667 | if strcmp(CellInfo{icell}.CoordType,'tps') %do not plot directly tps data (used for projection only)
|
---|
[402] | 668 | continue
|
---|
| 669 | end
|
---|
[530] | 670 | ivar_X=CellInfo{icell}.CoordIndex(end); % defines (unique) index for the variable representing unstructured x coordinate (default =[])
|
---|
| 671 | ivar_Y=CellInfo{icell}.CoordIndex(end-1); % defines (unique)index for the variable representing unstructured y coordinate (default =[])
|
---|
| 672 | ivar_C=[];
|
---|
| 673 | if isfield(CellInfo{icell},'VarIndex_scalar')
|
---|
| 674 | ivar_C=[ivar_C CellInfo{icell}.VarIndex_scalar];
|
---|
| 675 | end
|
---|
| 676 | if isfield(CellInfo{icell},'VarIndex_image')
|
---|
| 677 | ivar_C=[ivar_C CellInfo{icell}.VarIndex_image];
|
---|
| 678 | end
|
---|
| 679 | if isfield(CellInfo{icell},'VarIndex_color')
|
---|
| 680 | ivar_C=[ivar_C CellInfo{icell}.VarIndex_color];
|
---|
| 681 | end
|
---|
| 682 | if isfield(CellInfo{icell},'VarIndex_ancillary')
|
---|
| 683 | ivar_C=[ivar_C CellInfo{icell}.VarIndex_ancillary];
|
---|
| 684 | end
|
---|
[201] | 685 | if numel(ivar_C)>1
|
---|
| 686 | errormsg= 'error in plot_field: too many scalar inputs';
|
---|
| 687 | return
|
---|
| 688 | end
|
---|
[530] | 689 | ivar_F=[];
|
---|
| 690 | if isfield(CellInfo{icell},'VarIndex_warnflag')
|
---|
[674] | 691 | ivar_F=CellInfo{icell}.VarIndex_warnflag; %defines index (unique) for warning flag variable
|
---|
[201] | 692 | end
|
---|
[674] | 693 | ivar_FF_vec=[];
|
---|
[530] | 694 | if isfield(CellInfo{icell},'VarIndex_vector_x')&&isfield(CellInfo{icell},'VarIndex_vector_y') % vector components detected
|
---|
[674] | 695 | if test_vec% a vector field has been already detected
|
---|
[866] | 696 | errormsg='error in plot_field: attempt to plot two vector fields: to get the difference project on a plane with ProjMode= interp_lin or interp_tps';
|
---|
[201] | 697 | return
|
---|
| 698 | else
|
---|
[864] | 699 | if numel(CellInfo{icell}.VarIndex_vector_x)>1
|
---|
| 700 | errormsg='error in plot_field: attempt to plot two vector fields';
|
---|
[1031] | 701 | return
|
---|
[864] | 702 | end
|
---|
[201] | 703 | test_vec=1;
|
---|
[674] | 704 | if isfield(CellInfo{icell},'VarIndex_errorflag')
|
---|
| 705 | ivar_FF_vec=CellInfo{icell}.VarIndex_errorflag; %defines index (unique) for error flag variable
|
---|
| 706 | end
|
---|
| 707 | vec_U=Data.(Data.ListVarName{CellInfo{icell}.VarIndex_vector_x});
|
---|
[530] | 708 | vec_V=Data.(Data.ListVarName{CellInfo{icell}.VarIndex_vector_y});
|
---|
[1001] | 709 | XName=Data.ListVarName{CellInfo{icell}.CoordIndex(end)};
|
---|
| 710 | YName=Data.ListVarName{CellInfo{icell}.CoordIndex(end-1)};
|
---|
[674] | 711 | if strcmp(CellInfo{icell}.CoordType,'scattered')%2D field with unstructured coordinates
|
---|
[517] | 712 | vec_X=reshape(Data.(XName),[],1); %transform vectors in column matlab vectors
|
---|
| 713 | vec_Y=reshape(Data.(YName),[],1);
|
---|
[674] | 714 | elseif strcmp(CellInfo{icell}.CoordType,'grid')%2D field with structured coordinates
|
---|
[1001] | 715 | y=Data.(YName);
|
---|
| 716 | x=Data.(XName);
|
---|
[201] | 717 | if numel(y)==2 % y defined by first and last values on aregular mesh
|
---|
| 718 | y=linspace(y(1),y(2),size(vec_U,1));
|
---|
| 719 | end
|
---|
| 720 | if numel(x)==2 % y defined by first and last values on aregular mesh
|
---|
| 721 | x=linspace(x(1),x(2),size(vec_U,2));
|
---|
| 722 | end
|
---|
[674] | 723 | [vec_X,vec_Y]=meshgrid(x,y);
|
---|
[201] | 724 | end
|
---|
[517] | 725 | if isfield(PlotParam.Vectors,'ColorScalar') && ~isempty(PlotParam.Vectors.ColorScalar)
|
---|
| 726 | [VarVal,ListVarName,VarAttribute,errormsg]=calc_field_interp([],Data,PlotParam.Vectors.ColorScalar);
|
---|
[530] | 727 | if ~isempty(VarVal)
|
---|
| 728 | vec_C=reshape(VarVal{1},1,numel(VarVal{1}));
|
---|
| 729 | test_C=1;
|
---|
| 730 | end
|
---|
[201] | 731 | end
|
---|
[1144] | 732 |
|
---|
[674] | 733 | if ~isempty(ivar_FF_vec) %&& ~test_false
|
---|
[1031] | 734 | vec_FF=Data.(Data.ListVarName{ivar_FF_vec}); % flags for false vectors
|
---|
[1143] | 735 | if ~isempty(ivar_F)%~(isfield(PlotParam.Vectors,'HideWarning')&& isequal(PlotParam.Vectors.HideWarning,1))
|
---|
| 736 | vec_F=Data.(Data.ListVarName{ivar_F}); % warning flags for dubious vectors
|
---|
[1144] | 737 | vec_FF(find(vec_F==-2))=1;%set alseFlag to 1(edge of the search box)
|
---|
[1143] | 738 | end
|
---|
[201] | 739 | end
|
---|
| 740 | end
|
---|
| 741 | elseif ~isempty(ivar_C) %scalar or image
|
---|
| 742 | if test_ima
|
---|
[674] | 743 | errormsg='attempt to plot two scalar fields or images';
|
---|
[201] | 744 | return
|
---|
| 745 | end
|
---|
[530] | 746 | A=squeeze(Data.(Data.ListVarName{ivar_C}));% scalar represented as color image
|
---|
[201] | 747 | test_ima=1;
|
---|
[674] | 748 | if strcmp(CellInfo{icell}.CoordType,'scattered')%2D field with unstructured coordinates
|
---|
[227] | 749 | A=reshape(A,1,[]);
|
---|
[201] | 750 | XName=Data.ListVarName{ivar_X};
|
---|
| 751 | YName=Data.ListVarName{ivar_Y};
|
---|
[1001] | 752 | Coord_x=reshape(Data.(XName),1,[]);
|
---|
| 753 | Coord_y=reshape(Data.(YName),1,[]);
|
---|
[782] | 754 | [A,Coord_x,Coord_y]=proj_grid(Coord_x',Coord_y',A',[],[],'np>256'); % interpolate on a grid
|
---|
[201] | 755 | if isfield(Data,'VarAttribute')
|
---|
| 756 | if numel(Data.VarAttribute)>=ivar_X && isfield(Data.VarAttribute{ivar_X},'units')
|
---|
| 757 | x_units=[' (' Data.VarAttribute{ivar_X}.units ')'];
|
---|
| 758 | end
|
---|
| 759 | if numel(Data.VarAttribute)>=ivar_Y && isfield(Data.VarAttribute{ivar_Y},'units')
|
---|
| 760 | y_units=[' (' Data.VarAttribute{ivar_Y}.units ')'];
|
---|
| 761 | end
|
---|
[674] | 762 | end
|
---|
| 763 | elseif strcmp(CellInfo{icell}.CoordType,'grid')%2D field with structured coordinates
|
---|
[530] | 764 | YName=Data.ListVarName{CellInfo{icell}.CoordIndex(end-1)};
|
---|
[1001] | 765 | XName=Data.ListVarName{CellInfo{icell}.CoordIndex(end)};
|
---|
[782] | 766 | Coord_y=Data.(YName);
|
---|
[1001] | 767 | Coord_x=Data.(XName);
|
---|
[201] | 768 | test_interp_X=0; %default, regularly meshed X coordinate
|
---|
| 769 | test_interp_Y=0; %default, regularly meshed Y coordinate
|
---|
[1094] | 770 | % if isfield(Data,'VarAttribute')
|
---|
| 771 | % if numel(Data.VarAttribute)>=CellInfo{icell}.CoordIndex(end) && isfield(Data.VarAttribute{CellInfo{icell}.CoordIndex(end)},'units')
|
---|
| 772 | % x_units=Data.VarAttribute{CellInfo{icell}.CoordIndex(end)}.units;
|
---|
| 773 | % end
|
---|
| 774 | % if numel(Data.VarAttribute)>=CellInfo{icell}.CoordIndex(end-1) && isfield(Data.VarAttribute{CellInfo{icell}.CoordIndex(end-1)},'units')
|
---|
| 775 | % y_units=Data.VarAttribute{CellInfo{icell}.CoordIndex(end-1)}.units;
|
---|
| 776 | % end
|
---|
| 777 | % end
|
---|
[782] | 778 | if numel(Coord_y)>2
|
---|
| 779 | DCoord_y=diff(Coord_y);
|
---|
| 780 | DCoord_y_min=min(DCoord_y);
|
---|
| 781 | DCoord_y_max=max(DCoord_y);
|
---|
| 782 | if sign(DCoord_y_min)~=sign(DCoord_y_max);% =1 for increasing values, 0 otherwise
|
---|
[1001] | 783 | errormsg=['errror in plot_field.m: non monotonic dimension variable ' YName ];
|
---|
[674] | 784 | return
|
---|
| 785 | end
|
---|
[782] | 786 | test_interp_Y=(DCoord_y_max-DCoord_y_min)> 0.0001*abs(DCoord_y_max);
|
---|
[201] | 787 | end
|
---|
[782] | 788 | if numel(Coord_x)>2
|
---|
| 789 | DCoord_x=diff(Coord_x);
|
---|
| 790 | DCoord_x_min=min(DCoord_x);
|
---|
| 791 | DCoord_x_max=max(DCoord_x);
|
---|
[1094] | 792 | if sign(DCoord_x_min)~=sign(DCoord_x_max)% =1 for increasing values, 0 otherwise
|
---|
[674] | 793 | errormsg=['errror in plot_field.m: non monotonic dimension variable ' Data.ListVarName{VarRole.coord(2)} ];
|
---|
| 794 | return
|
---|
| 795 | end
|
---|
[782] | 796 | test_interp_X=(DCoord_x_max-DCoord_x_min)> 0.0001*abs(DCoord_x_max);
|
---|
[674] | 797 | end
|
---|
| 798 | if test_interp_Y
|
---|
[782] | 799 | npxy(1)=max([256 floor((Coord_y(end)-Coord_y(1))/DCoord_y_min) floor((Coord_y(end)-Coord_y(1))/DCoord_y_max)]);
|
---|
| 800 | yI=linspace(Coord_y(1),Coord_y(end),npxy(1));
|
---|
[201] | 801 | if ~test_interp_X
|
---|
[782] | 802 | xI=linspace(Coord_x(1),Coord_x(end),size(A,2));%default
|
---|
| 803 | Coord_x=xI;
|
---|
[201] | 804 | end
|
---|
| 805 | end
|
---|
[674] | 806 | if test_interp_X
|
---|
[782] | 807 | npxy(2)=max([256 floor((Coord_x(end)-Coord_x(1))/DCoord_x_min) floor((Coord_x(end)-Coord_x(1))/DCoord_x_max)]);
|
---|
| 808 | xI=linspace(Coord_x(1),Coord_x(end),npxy(2));
|
---|
[201] | 809 | if ~test_interp_Y
|
---|
[782] | 810 | yI=linspace(Coord_y(1),Coord_y(end),size(A,1));
|
---|
| 811 | Coord_y=yI;
|
---|
[201] | 812 | end
|
---|
| 813 | end
|
---|
[674] | 814 | if test_interp_X || test_interp_Y
|
---|
[782] | 815 | [Coord_x2D,Coord_y2D]=meshgrid(Coord_x,Coord_y);
|
---|
| 816 | A=interp2(Coord_x2D,Coord_y2D,double(A),xI,yI');
|
---|
[201] | 817 | end
|
---|
[782] | 818 | Coord_x=[Coord_x(1) Coord_x(end)];% keep only the lower and upper bounds for image represnetation
|
---|
| 819 | Coord_y=[Coord_y(1) Coord_y(end)];
|
---|
[201] | 820 | end
|
---|
| 821 | end
|
---|
| 822 | %define coordinates as CoordUnits, if not defined as attribute for each variable
|
---|
[1094] | 823 | % if isfield(Data,'VarAttribute')&& numel(Data.VarAttribute)>=1 && isfield(Data.VarAttribute{1},'unit')
|
---|
| 824 | % y_units=Data.VarAttribute{1}.unit;
|
---|
| 825 | % end
|
---|
[201] | 826 | if isfield(Data,'CoordUnit')
|
---|
| 827 | if isempty(x_units)
|
---|
| 828 | x_units=Data.CoordUnit;
|
---|
| 829 | end
|
---|
| 830 | if isempty(y_units)
|
---|
| 831 | y_units=Data.CoordUnit;
|
---|
| 832 | end
|
---|
[1094] | 833 | elseif isfield(Data,'VarAttribute')
|
---|
| 834 | if numel(Data.VarAttribute)>=CellInfo{icell}.CoordIndex(end) && isfield(Data.VarAttribute{CellInfo{icell}.CoordIndex(end)},'units')
|
---|
| 835 | x_units=Data.VarAttribute{CellInfo{icell}.CoordIndex(end)}.units;
|
---|
| 836 | end
|
---|
| 837 | if numel(Data.VarAttribute)>=CellInfo{icell}.CoordIndex(end-1) && isfield(Data.VarAttribute{CellInfo{icell}.CoordIndex(end-1)},'units')
|
---|
| 838 | y_units=Data.VarAttribute{CellInfo{icell}.CoordIndex(end-1)}.units;
|
---|
| 839 | end
|
---|
[1031] | 840 | end
|
---|
[674] | 841 | end
|
---|
[1031] | 842 |
|
---|
[688] | 843 | PlotParamOut=PlotParam; % output plot parameters equal to input by default
|
---|
[201] | 844 |
|
---|
| 845 | %% image or scalar plot %%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
| 846 | if test_ima
|
---|
| 847 | % distinguish B/W and color images
|
---|
| 848 | np=size(A);%size of image
|
---|
| 849 | siz=numel(np);
|
---|
| 850 | if siz>3
|
---|
[428] | 851 | errormsg=['unrecognized scalar type: ' num2str(siz) ' dimensions'];
|
---|
| 852 | return
|
---|
[201] | 853 | end
|
---|
| 854 | if siz==3
|
---|
| 855 | if np(3)==1
|
---|
[1133] | 856 | siz=2;%grey scale image
|
---|
[201] | 857 | elseif np(3)==3
|
---|
| 858 | siz=3;%color image
|
---|
| 859 | else
|
---|
[206] | 860 | errormsg=['unrecognized scalar type in plot_field: considered as 2D field with ' num2str(np(3)) ' color components'];
|
---|
[201] | 861 | return
|
---|
| 862 | end
|
---|
| 863 | end
|
---|
| 864 |
|
---|
[822] | 865 | %set for grey scale setting
|
---|
[1133] | 866 | ColorMap='default';%default colormap
|
---|
[421] | 867 | if isfield(PlotParam.Scalar,'CheckBW') && ~isempty(PlotParam.Scalar.CheckBW)
|
---|
[1103] | 868 | ColorMap=PlotParam.Scalar.CheckBW; %BW=0 color imposed, else gray scale imposed.
|
---|
| 869 | elseif ((siz==2) && (isa(A,'uint8')|| isa(A,'uint16')))% non color images represented in gray scale by default
|
---|
| 870 | ColorMap='grayscale';
|
---|
[428] | 871 | end
|
---|
[1103] | 872 | PlotParamOut.Scalar.CheckBW=ColorMap;
|
---|
[822] | 873 | % determine the plot option 'image' or 'contours'
|
---|
| 874 | CheckContour=0; %default
|
---|
[688] | 875 | if isfield(PlotParam.Scalar,'ListContour')
|
---|
| 876 | CheckContour=strcmp(PlotParam.Scalar.ListContour,'contours');% =1 for contour plot option
|
---|
[822] | 877 | end
|
---|
| 878 |
|
---|
| 879 | %case of grey level images or contour plot
|
---|
| 880 | if ~isfield(PlotParam.Scalar,'CheckFixScalar')
|
---|
| 881 | PlotParam.Scalar.CheckFixScalar=0;% free scalar threshold value scale (from min to max) by default
|
---|
| 882 | end
|
---|
| 883 | if ~isfield(PlotParam.Scalar,'MinA')
|
---|
| 884 | PlotParam.Scalar.MinA=[];%no min scalar threshold value set
|
---|
| 885 | end
|
---|
| 886 | if ~isfield(PlotParam.Scalar,'MaxA')
|
---|
| 887 | PlotParam.Scalar.MaxA=[];%no max scalar threshold value set
|
---|
| 888 | end
|
---|
| 889 |
|
---|
| 890 | % determine the min scalar value
|
---|
| 891 | if PlotParam.Scalar.CheckFixScalar && ~isempty(PlotParam.Scalar.MinA) && isnumeric(PlotParam.Scalar.MinA)
|
---|
| 892 | MinA=double(PlotParam.Scalar.MinA); % min value set as input
|
---|
[688] | 893 | else
|
---|
[822] | 894 | MinA=double(min(min(min(A)))); % min value set as min of non NaN scalar values
|
---|
[688] | 895 | end
|
---|
| 896 |
|
---|
[822] | 897 | % error if the input scalar is NaN everywhere
|
---|
| 898 | if isnan(MinA)
|
---|
| 899 | errormsg='NaN input scalar or image in plot_field';
|
---|
| 900 | return
|
---|
| 901 | end
|
---|
| 902 |
|
---|
| 903 | % determine the max scalar value
|
---|
| 904 | CheckFixScalar=0;
|
---|
| 905 | if PlotParam.Scalar.CheckFixScalar && ~isempty(PlotParam.Scalar.MaxA) && isnumeric(PlotParam.Scalar.MaxA)
|
---|
| 906 | MaxA=double(PlotParam.Scalar.MaxA); % max value set as input
|
---|
| 907 | CheckFixScalar=1;
|
---|
| 908 | else
|
---|
| 909 | MaxA=double(max(max(max(A)))); % max value set as min of non NaN scalar values
|
---|
| 910 | end
|
---|
| 911 |
|
---|
| 912 | PlotParamOut.Scalar.MinA=MinA;
|
---|
| 913 | PlotParamOut.Scalar.MaxA=MaxA;
|
---|
| 914 | PlotParamOut.Scalar.Npx=size(A,2);
|
---|
| 915 | PlotParamOut.Scalar.Npy=size(A,1);
|
---|
[1103] | 916 |
|
---|
[822] | 917 | % case of contour plot
|
---|
| 918 | if CheckContour
|
---|
| 919 | if ~isempty(hima) && ishandle(hima)
|
---|
| 920 | delete(hima) % delete existing image
|
---|
[201] | 921 | end
|
---|
[822] | 922 |
|
---|
| 923 | % set the contour values
|
---|
| 924 | if ~isfield(PlotParam.Scalar,'IncrA')
|
---|
| 925 | PlotParam.Scalar.IncrA=[];% automatic contour interval
|
---|
[201] | 926 | end
|
---|
[822] | 927 | if ~isempty(PlotParam.Scalar.IncrA) && isnumeric(PlotParam.Scalar.IncrA)
|
---|
| 928 | interval=PlotParam.Scalar.IncrA;
|
---|
| 929 | else % automatic contour interval
|
---|
| 930 | cont=colbartick(MinA,MaxA);
|
---|
| 931 | interval=cont(2)-cont(1);%default
|
---|
| 932 | PlotParamOut.Scalar.IncrA=interval;% set the interval as output for display on the GUI
|
---|
[201] | 933 | end
|
---|
[822] | 934 | abscontmin=interval*floor(MinA/interval);
|
---|
| 935 | abscontmax=interval*ceil(MaxA/interval);
|
---|
| 936 | contmin=interval*floor(min(min(A))/interval);
|
---|
| 937 | contmax=interval*ceil(max(max(A))/interval);
|
---|
| 938 | cont_pos_plus=0:interval:contmax;% zero and positive contour values (plotted as solid lines)
|
---|
| 939 | cont_pos_min=double(contmin):interval:-interval;% negative contour values (plotted as dashed lines)
|
---|
| 940 | cont_pos=[cont_pos_min cont_pos_plus];% set of all contour values
|
---|
[688] | 941 |
|
---|
[822] | 942 | sizpx=(Coord_x(end)-Coord_x(1))/(np(2)-1);
|
---|
| 943 | sizpy=(Coord_y(1)-Coord_y(end))/(np(1)-1);
|
---|
| 944 | x_cont=Coord_x(1):sizpx:Coord_x(end); % pixel x coordinates for image display
|
---|
| 945 | y_cont=Coord_y(1):-sizpy:Coord_y(end); % pixel x coordinates for image display
|
---|
[688] | 946 |
|
---|
[822] | 947 | tag_axes=get(haxes,'Tag');% axes tag
|
---|
| 948 | Opacity=1;
|
---|
| 949 | if isfield(PlotParam.Scalar,'Opacity')&&~isempty(PlotParam.Scalar.Opacity)
|
---|
| 950 | Opacity=PlotParam.Scalar.Opacity;
|
---|
[688] | 951 | end
|
---|
[822] | 952 | % fill the space between contours if opacity is undefined or =1
|
---|
| 953 | if isequal(Opacity,1)
|
---|
| 954 | [var,hcontour]=contour(haxes,x_cont,y_cont,A,cont_pos);% determine all contours
|
---|
| 955 | set(hcontour,'Fill','on')% fill the space between contours
|
---|
| 956 | set(hcontour,'LineStyle','none')
|
---|
| 957 | hold on
|
---|
| 958 | end
|
---|
| 959 | [var_p,hcontour_p]=contour(haxes,x_cont,y_cont,A,cont_pos_plus,'k-');% draw the contours for positive values as solid lines
|
---|
| 960 | hold on
|
---|
| 961 | [var_m,hcontour_m]=contour(haxes,x_cont,y_cont,A,cont_pos_min,'--');% draw the contours for negative values as dashed lines
|
---|
| 962 | if isequal(Opacity,1)
|
---|
| 963 | set(hcontour_m,'LineColor',[1 1 1])% draw negative contours in white (better visibility in dark background)
|
---|
| 964 | end
|
---|
| 965 | set(haxes,'Tag',tag_axes);% restore axes tag (removed by the matlab fct contour !)
|
---|
| 966 | hold off
|
---|
[688] | 967 |
|
---|
[822] | 968 | %determine the color scale and map
|
---|
| 969 | caxis([abscontmin abscontmax])
|
---|
[1103] | 970 | if strcmp(ColorMap,'grayscale')
|
---|
[822] | 971 | vec=linspace(0,1,(abscontmax-abscontmin)/interval);%define a greyscale colormap with steps interval
|
---|
| 972 | map=[vec' vec' vec'];
|
---|
| 973 | colormap(map);
|
---|
[1103] | 974 | elseif strcmp(ColorMap,'BuYlRd')
|
---|
| 975 | hh=load('BuYlRd.mat');
|
---|
| 976 | colormap(hh.BuYlRd);
|
---|
[201] | 977 | else
|
---|
[1103] | 978 | colormap(ColorMap);
|
---|
[822] | 979 | end
|
---|
| 980 | else %usual images (no contour)
|
---|
[201] | 981 | % set colormap for image display
|
---|
[1131] | 982 | switch ColorMap
|
---|
| 983 | case 'grayscale'
|
---|
| 984 | vec=linspace(0,1,255);%define a linear greyscale colormap
|
---|
| 985 | map=[vec' vec' vec'];
|
---|
| 986 | colormap(map); %grey scale color map
|
---|
| 987 | if siz==3% true color images visualized in BW
|
---|
| 988 | A=uint16(sum(A,3));%sum the three color components for color images displayed with BW option
|
---|
| 989 | end
|
---|
| 990 | case 'BuYlRd'
|
---|
| 991 | hh=load('BuYlRd.mat');
|
---|
| 992 | colormap(hh.BuYlRd);
|
---|
| 993 | case 'truecolor'
|
---|
| 994 | if siz==3 && CheckFixScalar % true color images rescaled by MaxA
|
---|
| 995 | A=uint8(255*double(A)/double(MaxA));
|
---|
| 996 | end
|
---|
[1133] | 997 | otherwise
|
---|
| 998 | colormap(ColorMap);
|
---|
[201] | 999 | end
|
---|
[1131] | 1000 |
|
---|
[201] | 1001 |
|
---|
| 1002 | % interpolate field to increase resolution of image display
|
---|
[652] | 1003 | test_interp=0;
|
---|
[822] | 1004 | if size(A,3)==1 % scalar or B/W image
|
---|
[652] | 1005 | test_interp=1;
|
---|
| 1006 | if max(np) <= 64
|
---|
| 1007 | npxy=8*np;% increase the resolution 8 times
|
---|
| 1008 | elseif max(np) <= 128
|
---|
| 1009 | npxy=4*np;% increase the resolution 4 times
|
---|
| 1010 | elseif max(np) <= 256
|
---|
| 1011 | npxy=2*np;% increase the resolution 2 times
|
---|
| 1012 | else
|
---|
| 1013 | npxy=np;
|
---|
| 1014 | test_interp=0; % no interpolation done
|
---|
| 1015 | end
|
---|
[201] | 1016 | end
|
---|
[652] | 1017 | if test_interp%if we interpolate
|
---|
[782] | 1018 | x=linspace(Coord_x(1),Coord_x(2),np(2));
|
---|
| 1019 | y=linspace(Coord_y(1),Coord_y(2),np(1));
|
---|
[201] | 1020 | [X,Y]=meshgrid(x,y);
|
---|
[782] | 1021 | xi=linspace(Coord_x(1),Coord_x(2),npxy(2));
|
---|
| 1022 | yi=linspace(Coord_y(1),Coord_y(2),npxy(1));
|
---|
[688] | 1023 | A = interp2(X,Y,double(A),xi,yi');
|
---|
[428] | 1024 | end
|
---|
[848] | 1025 | % create new image if no image handle is found
|
---|
[428] | 1026 | if isempty(hima)
|
---|
[201] | 1027 | tag=get(haxes,'Tag');
|
---|
| 1028 | if MinA<MaxA
|
---|
[782] | 1029 | hima=imagesc(Coord_x,Coord_y,A,[MinA MaxA]);
|
---|
[201] | 1030 | else % to deal with uniform field
|
---|
[782] | 1031 | hima=imagesc(Coord_x,Coord_y,A,[MaxA-1 MaxA]);
|
---|
[201] | 1032 | end
|
---|
[428] | 1033 | % the function imagesc reset the axes 'DataAspectRatioMode'='auto', change if .CheckFixAspectRatio is
|
---|
[411] | 1034 | % requested:
|
---|
| 1035 | set(hima,'Tag','ima')
|
---|
| 1036 | set(hima,'HitTest','off')
|
---|
[428] | 1037 | set(haxes,'Tag',tag);%preserve the axes tag (removed by image fct !!!)
|
---|
[201] | 1038 | uistack(hima, 'bottom')
|
---|
[428] | 1039 | % update an existing image
|
---|
[201] | 1040 | else
|
---|
[688] | 1041 | set(hima,'CData',A);
|
---|
[201] | 1042 | if MinA<MaxA
|
---|
| 1043 | set(haxes,'CLim',[MinA MaxA])
|
---|
| 1044 | else
|
---|
[238] | 1045 | set(haxes,'CLim',[MinA MaxA+1])
|
---|
[201] | 1046 | end
|
---|
[782] | 1047 | set(hima,'XData',Coord_x);
|
---|
| 1048 | set(hima,'YData',Coord_y);
|
---|
[201] | 1049 | end
|
---|
[546] | 1050 |
|
---|
[405] | 1051 | % set the transparency to 0.5 if vectors are also plotted
|
---|
[428] | 1052 | if isfield(PlotParam.Scalar,'Opacity')&& ~isempty(PlotParam.Scalar.Opacity)
|
---|
| 1053 | set(hima,'AlphaData',PlotParam.Scalar.Opacity)
|
---|
[405] | 1054 | else
|
---|
[428] | 1055 | if test_vec
|
---|
| 1056 | set(hima,'AlphaData',0.5)%set opacity to 0.5 by default in the presence of vectors
|
---|
| 1057 | PlotParamOut.Scalar.Opacity=0.5;
|
---|
| 1058 | else
|
---|
| 1059 | set(hima,'AlphaData',1)% full opacity (no transparency) by default
|
---|
| 1060 | end
|
---|
[405] | 1061 | end
|
---|
[201] | 1062 | end
|
---|
[1090] | 1063 | if isfield(PlotParam.Axes,'CheckFixAspectRatio') && isequal(PlotParam.Axes.CheckFixAspectRatio,1)
|
---|
| 1064 | set(haxes,'DataAspectRatioMode','manual')
|
---|
| 1065 | if isfield(PlotParam.Axes,'AspectRatio')
|
---|
| 1066 | set(haxes,'DataAspectRatio',[PlotParam.Axes.AspectRatio 1 1])
|
---|
| 1067 | else
|
---|
| 1068 | set(haxes,'DataAspectRatio',[1 1 1])
|
---|
| 1069 | end
|
---|
| 1070 | end
|
---|
[201] | 1071 | test_ima=1;
|
---|
| 1072 |
|
---|
| 1073 | %display the colorbar code for B/W images if Poscolorbar not empty
|
---|
[546] | 1074 | if ~isempty(PosColorbar)
|
---|
[822] | 1075 | if size(A,3)==1 && exist('PosColorbar','var')
|
---|
[546] | 1076 | if isempty(hcol)||~ishandle(hcol)
|
---|
| 1077 | hcol=colorbar;%create new colorbar
|
---|
| 1078 | end
|
---|
| 1079 | if length(PosColorbar)==4
|
---|
| 1080 | set(hcol,'Position',PosColorbar)
|
---|
| 1081 | end
|
---|
| 1082 | %YTick=0;%default
|
---|
| 1083 | if MaxA>MinA
|
---|
| 1084 | if CheckContour
|
---|
| 1085 | colbarlim=get(hcol,'YLim');
|
---|
| 1086 | scale_bar=(colbarlim(2)-colbarlim(1))/(abscontmax-abscontmin);
|
---|
| 1087 | YTick=cont_pos(2:end-1);
|
---|
| 1088 | YTick_scaled=colbarlim(1)+scale_bar*(YTick-abscontmin);
|
---|
| 1089 | set(hcol,'YTick',YTick_scaled);
|
---|
| 1090 | elseif (isfield(PlotParam.Scalar,'CheckBW') && isequal(PlotParam.Scalar.CheckBW,1))||isa(A,'uint8')|| isa(A,'uint16')%images
|
---|
| 1091 | hi=get(hcol,'children');
|
---|
| 1092 | if iscell(hi)%multiple images in colorbar
|
---|
| 1093 | hi=hi{1};
|
---|
| 1094 | end
|
---|
| 1095 | set(hi,'YData',[MinA MaxA])
|
---|
| 1096 | set(hi,'CData',(1:256)')
|
---|
| 1097 | set(hcol,'YLim',[MinA MaxA])
|
---|
| 1098 | YTick=colbartick(MinA,MaxA);
|
---|
| 1099 | set(hcol,'YTick',YTick)
|
---|
| 1100 | else
|
---|
| 1101 | hi=get(hcol,'children');
|
---|
| 1102 | if iscell(hi)%multiple images in colorbar
|
---|
| 1103 | hi=hi{1};
|
---|
| 1104 | end
|
---|
| 1105 | set(hi,'YData',[MinA MaxA])
|
---|
| 1106 | set(hi,'CData',(1:64)')
|
---|
| 1107 | YTick=colbartick(MinA,MaxA);
|
---|
| 1108 | set(hcol,'YLim',[MinA MaxA])
|
---|
| 1109 | set(hcol,'YTick',YTick)
|
---|
[201] | 1110 | end
|
---|
[546] | 1111 | set(hcol,'Yticklabel',num2str(YTick'));
|
---|
[201] | 1112 | end
|
---|
[546] | 1113 | elseif ishandle(hcol)
|
---|
| 1114 | delete(hcol); %erase existing colorbar if not needed
|
---|
[201] | 1115 | end
|
---|
| 1116 | end
|
---|
| 1117 | else%no scalar plot
|
---|
[428] | 1118 | if ~isempty(hima) && ishandle(hima)
|
---|
[201] | 1119 | delete(hima)
|
---|
| 1120 | end
|
---|
[546] | 1121 | if ~isempty(PosColorbar) && ~isempty(hcol)&& ishandle(hcol)
|
---|
[428] | 1122 | delete(hcol)
|
---|
[201] | 1123 | end
|
---|
| 1124 | PlotParamOut=rmfield(PlotParamOut,'Scalar');
|
---|
| 1125 | end
|
---|
| 1126 |
|
---|
| 1127 | %% vector plot %%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
| 1128 | if test_vec
|
---|
| 1129 | %vector scale representation
|
---|
[1103] | 1130 | if size(vec_U,1)==numel(vec_Y) && size(vec_U,2)==numel(vec_X) % x, y coordinate variables
|
---|
[201] | 1131 | [vec_X,vec_Y]=meshgrid(vec_X,vec_Y);
|
---|
| 1132 | end
|
---|
| 1133 | vec_X=reshape(vec_X,1,numel(vec_X));%reshape in matlab vectors
|
---|
| 1134 | vec_Y=reshape(vec_Y,1,numel(vec_Y));
|
---|
| 1135 | vec_U=reshape(vec_U,1,numel(vec_U));
|
---|
| 1136 | vec_V=reshape(vec_V,1,numel(vec_V));
|
---|
| 1137 | MinMaxX=max(vec_X)-min(vec_X);
|
---|
[294] | 1138 | if isfield(PlotParam.Vectors,'CheckFixVectors') && isequal(PlotParam.Vectors.CheckFixVectors,1)&& isfield(PlotParam.Vectors,'VecScale')...
|
---|
[210] | 1139 | &&~isempty(PlotParam.Vectors.VecScale) && isa(PlotParam.Vectors.VecScale,'double') %fixed vector scale
|
---|
| 1140 | scale=PlotParam.Vectors.VecScale; %impose the length of vector representation
|
---|
| 1141 | else
|
---|
| 1142 | if ~test_false %remove false vectors
|
---|
[201] | 1143 | indsel=1:numel(vec_X);%
|
---|
| 1144 | end
|
---|
| 1145 | if isempty(vec_U)
|
---|
| 1146 | scale=1;
|
---|
| 1147 | else
|
---|
| 1148 | if isempty(indsel)
|
---|
| 1149 | MaxU=max(abs(vec_U));
|
---|
| 1150 | MaxV=max(abs(vec_V));
|
---|
| 1151 | else
|
---|
| 1152 | MaxU=max(abs(vec_U(indsel)));
|
---|
| 1153 | MaxV=max(abs(vec_V(indsel)));
|
---|
| 1154 | end
|
---|
| 1155 | scale=MinMaxX/(max(MaxU,MaxV)*50);
|
---|
| 1156 | PlotParam.Vectors.VecScale=scale;%update the 'scale' display
|
---|
| 1157 | end
|
---|
[210] | 1158 | end
|
---|
[201] | 1159 |
|
---|
| 1160 | %record vectors on the plotting axes
|
---|
| 1161 | if test_C==0
|
---|
| 1162 | vec_C=ones(1,numel(vec_X));
|
---|
| 1163 | end
|
---|
| 1164 |
|
---|
| 1165 | %decimate by a factor 2 in vector mesh(4 in nbre of vectors)
|
---|
[581] | 1166 | check_decimate=0;
|
---|
[294] | 1167 | if isfield(PlotParam.Vectors,'CheckDecimate4') && PlotParam.Vectors.CheckDecimate4
|
---|
[581] | 1168 | check_decimate=1;
|
---|
[201] | 1169 | diffy=diff(vec_Y); %difference dy=vec_Y(i+1)-vec_Y(i)
|
---|
| 1170 | dy_thresh=max(abs(diffy))/2;
|
---|
| 1171 | ind_jump=find(abs(diffy) > dy_thresh); %indices with diff(vec_Y)> max/2, detect change of line
|
---|
| 1172 | ind_sel=1:ind_jump(1);%select the first line
|
---|
| 1173 | for i=2:2:length(ind_jump)-1
|
---|
| 1174 | ind_sel=[ind_sel (ind_jump(i)+1:ind_jump(i+1))];% select the odd lines
|
---|
| 1175 | end
|
---|
| 1176 | nb_sel=length(ind_sel);
|
---|
| 1177 | ind_sel=ind_sel(1:2:nb_sel);% take half the points on a line
|
---|
[581] | 1178 | elseif isfield(PlotParam.Vectors,'CheckDecimate16') && PlotParam.Vectors.CheckDecimate16
|
---|
| 1179 | check_decimate=1;
|
---|
| 1180 | diffy=diff(vec_Y); %difference dy=vec_Y(i+1)-vec_Y(i)
|
---|
| 1181 | dy_thresh=max(abs(diffy))/2;
|
---|
| 1182 | ind_jump=find(abs(diffy) > dy_thresh); %indices with diff(vec_Y)> max/2, detect change of line
|
---|
| 1183 | ind_sel=1:ind_jump(1);%select the first line
|
---|
| 1184 | for i=2:4:length(ind_jump)-1
|
---|
| 1185 | ind_sel=[ind_sel (ind_jump(i)+1:ind_jump(i+1))];% select the odd lines
|
---|
| 1186 | end
|
---|
| 1187 | nb_sel=length(ind_sel);
|
---|
| 1188 | ind_sel=ind_sel(1:4:nb_sel);% take half the points on a line
|
---|
| 1189 | end
|
---|
| 1190 | if check_decimate
|
---|
[201] | 1191 | vec_X=vec_X(ind_sel);
|
---|
| 1192 | vec_Y=vec_Y(ind_sel);
|
---|
| 1193 | vec_U=vec_U(ind_sel);
|
---|
| 1194 | vec_V=vec_V(ind_sel);
|
---|
| 1195 | vec_C=vec_C(ind_sel);
|
---|
[1143] | 1196 | % if ~isempty(ivar_F)
|
---|
| 1197 | % vec_F=vec_F(ind_sel);
|
---|
| 1198 | % end
|
---|
[674] | 1199 | if ~isempty(ivar_FF_vec)
|
---|
[201] | 1200 | vec_FF=vec_FF(ind_sel);
|
---|
| 1201 | end
|
---|
| 1202 | end
|
---|
| 1203 |
|
---|
| 1204 | %get main level color code
|
---|
| 1205 | [colorlist,col_vec,PlotParamOut.Vectors]=set_col_vec(PlotParam.Vectors,vec_C);
|
---|
| 1206 |
|
---|
| 1207 | % take flags into account: add flag colors to the list of colors
|
---|
[1103] | 1208 | nbcolor=size(colorlist,1);
|
---|
[1143] | 1209 | % % % if test_black
|
---|
| 1210 | % % % nbcolor=nbcolor+1;
|
---|
| 1211 | % % % colorlist(nbcolor,:)=[0 0 0]; %add black to the list of colors
|
---|
| 1212 | % % % if ~isempty(ivar_FF_vec)
|
---|
| 1213 | % % % col_vec(vec_F~=1 & vec_F~=0 & vec_FF==0)=nbcolor;
|
---|
| 1214 | % % % else
|
---|
| 1215 | % % % col_vec(vec_F~=1 & vec_F~=0)=nbcolor;
|
---|
| 1216 | % % % end
|
---|
| 1217 | % % % end
|
---|
[201] | 1218 | nbcolor=nbcolor+1;
|
---|
[674] | 1219 | if ~isempty(ivar_FF_vec)
|
---|
[1143] | 1220 | if isfield(PlotParam.Vectors,'CheckShowFalse') && PlotParam.Vectors.CheckShowFalse==1
|
---|
[1152] | 1221 | colorlist(nbcolor,:)=[1 0 1];% magenta color
|
---|
| 1222 | %colorlist(nbcolor,:)=[0 0 0];% blackcolor
|
---|
[1143] | 1223 | if strcmp(PlotParam.Vectors.FalseCriteria,'ALL')
|
---|
| 1224 | col_vec(vec_FF~=0)=nbcolor;
|
---|
| 1225 | else
|
---|
| 1226 | ind_dot=regexp(PlotParam.Vectors.FalseCriteria,':');
|
---|
| 1227 | FalseValue=str2num(PlotParam.Vectors.FalseCriteria(1:ind_dot-1));%get the selected flg number
|
---|
| 1228 | col_vec(vec_FF==FalseValue)=nbcolor;
|
---|
| 1229 | nbcolor=nbcolor+1;
|
---|
| 1230 | colorlist(nbcolor,:)=[NaN NaN NaN];%
|
---|
| 1231 | col_vec(vec_FF~=0 & vec_FF~=FalseValue)=nbcolor;
|
---|
| 1232 | end
|
---|
| 1233 | else
|
---|
[201] | 1234 | colorlist(nbcolor,:)=[NaN NaN NaN];% no plot of false vectors
|
---|
[1143] | 1235 | col_vec(vec_FF~=0)=nbcolor;
|
---|
| 1236 | end
|
---|
[201] | 1237 | end
|
---|
| 1238 | %plot vectors:
|
---|
| 1239 | quiresetn(haxes,vec_X,vec_Y,vec_U,vec_V,scale,colorlist,col_vec);
|
---|
| 1240 | else
|
---|
| 1241 | hvec=findobj(haxes,'Tag','vel');
|
---|
| 1242 | if ~isempty(hvec)
|
---|
| 1243 | delete(hvec);
|
---|
| 1244 | end
|
---|
| 1245 | PlotParamOut=rmfield(PlotParamOut,'Vectors');
|
---|
| 1246 | end
|
---|
| 1247 |
|
---|
| 1248 | %store the coordinate extrema occupied by the field
|
---|
| 1249 | if ~isempty(Data)
|
---|
[569] | 1250 | MinX=[];
|
---|
| 1251 | MaxX=[];
|
---|
| 1252 | MinY=[];
|
---|
| 1253 | MaxY=[];
|
---|
[748] | 1254 | fix_lim=isfield(PlotParam.Axes,'CheckFixLimits') && PlotParam.Axes.CheckFixLimits;
|
---|
[201] | 1255 | if fix_lim
|
---|
[748] | 1256 | if isfield(PlotParam.Axes,'MinX')&&isfield(PlotParam.Axes,'MaxX')&&isfield(PlotParam.Axes,'MinY')&&isfield(PlotParam.Axes,'MaxY')
|
---|
| 1257 | MinX=PlotParam.Axes.MinX;
|
---|
| 1258 | MaxX=PlotParam.Axes.MaxX;
|
---|
| 1259 | MinY=PlotParam.Axes.MinY;
|
---|
| 1260 | MaxY=PlotParam.Axes.MaxY;
|
---|
[569] | 1261 | end %else PlotParamOut.MinX =PlotParam.MinX...
|
---|
[252] | 1262 | else
|
---|
| 1263 | if test_ima %both background image and vectors coexist, take the wider bound
|
---|
[782] | 1264 | MinX=min(Coord_x);
|
---|
| 1265 | MaxX=max(Coord_x);
|
---|
| 1266 | MinY=min(Coord_y);
|
---|
| 1267 | MaxY=max(Coord_y);
|
---|
[252] | 1268 | if test_vec
|
---|
[569] | 1269 | MinX=min(MinX,min(vec_X));
|
---|
| 1270 | MaxX=max(MaxX,max(vec_X));
|
---|
| 1271 | MinY=min(MinY,min(vec_Y));
|
---|
| 1272 | MaxY=max(MaxY,max(vec_Y));
|
---|
[252] | 1273 | end
|
---|
| 1274 | elseif test_vec
|
---|
[569] | 1275 | MinX=min(vec_X);
|
---|
| 1276 | MaxX=max(vec_X);
|
---|
| 1277 | MinY=min(vec_Y);
|
---|
| 1278 | MaxY=max(vec_Y);
|
---|
[201] | 1279 | end
|
---|
[252] | 1280 | end
|
---|
[748] | 1281 | PlotParamOut.Axes.MinX=MinX;
|
---|
| 1282 | PlotParamOut.Axes.MaxX=MaxX;
|
---|
| 1283 | PlotParamOut.Axes.MinY=MinY;
|
---|
| 1284 | PlotParamOut.Axes.MaxY=MaxY;
|
---|
[569] | 1285 | if MaxX>MinX
|
---|
| 1286 | set(haxes,'XLim',[MinX MaxX]);% set x limits of frame in axes coordinates
|
---|
[546] | 1287 | end
|
---|
[569] | 1288 | if MaxY>MinY
|
---|
| 1289 | set(haxes,'YLim',[MinY MaxY]);% set x limits of frame in axes coordinates
|
---|
[546] | 1290 | end
|
---|
[201] | 1291 | set(haxes,'YDir','normal')
|
---|
| 1292 | set(get(haxes,'XLabel'),'String',[XName ' (' x_units ')']);
|
---|
| 1293 | set(get(haxes,'YLabel'),'String',[YName ' (' y_units ')']);
|
---|
[748] | 1294 | PlotParamOut.Axes.x_units=x_units;
|
---|
| 1295 | PlotParamOut.Axes.y_units=y_units;
|
---|
[201] | 1296 | end
|
---|
[760] | 1297 |
|
---|
[201] | 1298 | %-------------------------------------------------------------------
|
---|
| 1299 | % --- function for plotting vectors
|
---|
| 1300 | %INPUT:
|
---|
| 1301 | % haxes: handles of the plotting axes
|
---|
| 1302 | % x,y,u,v: vectors coordinates and vector components to plot, arrays withb the same dimension
|
---|
| 1303 | % scale: scaling factor for vector length representation
|
---|
| 1304 | % colorlist(icolor,:): list of vector colors, dim (nbcolor,3), depending on color #i
|
---|
| 1305 | % col_vec: matlab vector setting the color number #i for each velocity vector
|
---|
| 1306 | function quiresetn(haxes,x,y,u,v,scale,colorlist,col_vec)
|
---|
| 1307 | %-------------------------------------------------------------------
|
---|
| 1308 | %define arrows
|
---|
| 1309 | theta=0.5 ;%angle arrow
|
---|
| 1310 | alpha=0.3 ;%length arrow
|
---|
| 1311 | rot=alpha*[cos(theta) -sin(theta); sin(theta) cos(theta)]';
|
---|
[1103] | 1312 |
|
---|
[201] | 1313 | %find the existing lines
|
---|
| 1314 | h=findobj(haxes,'Tag','vel');% search existing lines in the current axes
|
---|
| 1315 | sizh=size(h);
|
---|
| 1316 | set(haxes,'NextPlot','replacechildren');
|
---|
| 1317 |
|
---|
| 1318 | %create lines (if no lines) or modify them
|
---|
| 1319 | if ~isequal(size(col_vec),size(x))
|
---|
| 1320 | col_vec=ones(size(x));% case of error in col_vec input
|
---|
| 1321 | end
|
---|
[1103] | 1322 | nbcolor=size(colorlist,1);
|
---|
[201] | 1323 |
|
---|
[1103] | 1324 | for icolor=1:nbcolor
|
---|
[201] | 1325 | %determine the line positions for each color icolor
|
---|
| 1326 | ind=find(col_vec==icolor);
|
---|
| 1327 | xc=x(ind);
|
---|
| 1328 | yc=y(ind);
|
---|
| 1329 | uc=u(ind)*scale;
|
---|
| 1330 | vc=v(ind)*scale;
|
---|
| 1331 | n=size(xc);
|
---|
| 1332 | xN=NaN*ones(size(xc));
|
---|
| 1333 | matx=[xc(:)-uc(:)/2 xc(:)+uc(:)/2 xN(:)]';
|
---|
| 1334 | matx=reshape(matx,1,3*n(2));
|
---|
| 1335 | maty=[yc(:)-vc(:)/2 yc(:)+vc(:)/2 xN(:)]';
|
---|
| 1336 | maty=reshape(maty,1,3*n(2));
|
---|
| 1337 |
|
---|
| 1338 | %determine arrow heads
|
---|
| 1339 | arrowplus=rot*[uc;vc];
|
---|
| 1340 | arrowmoins=rot'*[uc;vc];
|
---|
| 1341 | x1=xc+uc/2-arrowplus(1,:);
|
---|
| 1342 | x2=xc+uc/2;
|
---|
| 1343 | x3=xc+uc/2-arrowmoins(1,:);
|
---|
| 1344 | y1=yc+vc/2-arrowplus(2,:);
|
---|
| 1345 | y2=yc+vc/2;
|
---|
| 1346 | y3=yc+vc/2-arrowmoins(2,:);
|
---|
| 1347 | matxar=[x1(:) x2(:) x3(:) xN(:)]';
|
---|
| 1348 | matxar=reshape(matxar,1,4*n(2));
|
---|
| 1349 | matyar=[y1(:) y2(:) y3(:) xN(:)]';
|
---|
| 1350 | matyar=reshape(matyar,1,4*n(2));
|
---|
| 1351 | %draw the line or modify the existing ones
|
---|
[421] | 1352 | % tri=reshape(1:3*length(uc),3,[])';
|
---|
[201] | 1353 | isn=isnan(colorlist(icolor,:));%test if color NaN
|
---|
| 1354 | if 2*icolor > sizh(1) %if icolor exceeds the number of existing ones
|
---|
| 1355 | if ~isn(1) %if the vectors are visible color not nan
|
---|
| 1356 | if n(2)>0
|
---|
| 1357 | hold on
|
---|
| 1358 | line(matx,maty,'Color',colorlist(icolor,:),'Tag','vel');% plot new lines
|
---|
| 1359 | line(matxar,matyar,'Color',colorlist(icolor,:),'Tag','vel');% plot arrows
|
---|
| 1360 | end
|
---|
| 1361 | end
|
---|
| 1362 | else
|
---|
| 1363 | if isn(1)
|
---|
| 1364 | delete(h(2*icolor-1))
|
---|
| 1365 | delete(h(2*icolor))
|
---|
| 1366 | else
|
---|
| 1367 | set(h(2*icolor-1),'Xdata',matx,'Ydata',maty);
|
---|
| 1368 | set(h(2*icolor-1),'Color',colorlist(icolor,:));
|
---|
[932] | 1369 | % set(h(2*icolor-1),'EraseMode','xor');
|
---|
[201] | 1370 | set(h(2*icolor),'Xdata',matxar,'Ydata',matyar);
|
---|
| 1371 | set(h(2*icolor),'Color',colorlist(icolor,:));
|
---|
[932] | 1372 | %set(h(2*icolor),'EraseMode','xor');
|
---|
[201] | 1373 | end
|
---|
| 1374 | end
|
---|
| 1375 | end
|
---|
[1103] | 1376 | if sizh(1) > 2*nbcolor
|
---|
| 1377 | for icolor=nbcolor+1 : sizh(1)/2 %delete additional objects
|
---|
[201] | 1378 | delete(h(2*icolor-1))
|
---|
| 1379 | delete(h(2*icolor))
|
---|
| 1380 | end
|
---|
| 1381 | end
|
---|
| 1382 |
|
---|
| 1383 | %-------------------------------------------------------------------
|
---|
| 1384 | % ---- determine tick positions for colorbar
|
---|
| 1385 | function YTick=colbartick(MinA,MaxA)
|
---|
| 1386 | %-------------------------------------------------------------------
|
---|
| 1387 | %determine tick positions with "simple" values between MinA and MaxA
|
---|
| 1388 | YTick=0;%default
|
---|
| 1389 | maxabs=max([abs(MinA) abs(MaxA)]);
|
---|
| 1390 | if maxabs>0
|
---|
| 1391 | ord=10^(floor(log10(maxabs)));%order of magnitude
|
---|
| 1392 | div=1;
|
---|
| 1393 | siz2=1;
|
---|
| 1394 | while siz2<2
|
---|
| 1395 | values=-10:div:10;
|
---|
| 1396 | ind=find((ord*values-MaxA)<0 & (ord*values-MinA)>0);%indices of 'values' such that MinA<ord*values<MaxA
|
---|
| 1397 | siz=size(ind);
|
---|
| 1398 | if siz(2)<4%if there are less than 4 selected values (4 levels)
|
---|
| 1399 | values=-9:0.5*div:9;
|
---|
| 1400 | ind=find((ord*values-MaxA)<0 & (ord*values-MinA)>0);
|
---|
| 1401 | end
|
---|
| 1402 | siz2=size(ind,2);
|
---|
| 1403 | div=div/10;
|
---|
| 1404 | end
|
---|
| 1405 | YTick=ord*values(ind);
|
---|
| 1406 | end
|
---|
| 1407 |
|
---|
[356] | 1408 | % -------------------------------------------------------------------------
|
---|
[389] | 1409 | % --- 'proj_grid': project fields with unstructured coordinantes on a regular grid
|
---|
[356] | 1410 | function [A,rangx,rangy]=proj_grid(vec_X,vec_Y,vec_A,rgx_in,rgy_in,npxy_in)
|
---|
[389] | 1411 | % -------------------------------------------------------------------------
|
---|
[356] | 1412 | if length(vec_Y)<2
|
---|
| 1413 | msgbox_uvmat('ERROR','less than 2 points in proj_grid.m');
|
---|
| 1414 | return;
|
---|
| 1415 | end
|
---|
| 1416 | diffy=diff(vec_Y); %difference dy=vec_Y(i+1)-vec_Y(i)
|
---|
| 1417 | index=find(diffy);% find the indices of vec_Y after wich a change of horizontal line occurs(diffy non zero)
|
---|
| 1418 | if isempty(index); msgbox_uvmat('ERROR','points aligned along abscissa in proj_grid.m'); return; end;%points aligned% A FAIRE: switch to line plot.
|
---|
| 1419 | diff2=diff(diffy(index));% diff2 = fluctuations of the detected vertical grid mesh dy
|
---|
| 1420 | if max(abs(diff2))>0.001*abs(diffy(index(1))) % if max(diff2) is larger than 1/1000 of the first mesh dy
|
---|
| 1421 | % the data are not regularly spaced and must be interpolated on a regular grid
|
---|
| 1422 | if exist('rgx_in','var') & ~isempty (rgx_in) & isnumeric(rgx_in) & length(rgx_in)==2% positions imposed from input
|
---|
| 1423 | rangx=rgx_in; % first and last positions
|
---|
| 1424 | rangy=rgy_in;
|
---|
| 1425 | dxy(1)=1/(npxy_in(1)-1);%grid mesh in y
|
---|
| 1426 | dxy(2)=1/(npxy_in(2)-1);%grid mesh in x
|
---|
| 1427 | dxy(1)=(rangy(2)-rangy(1))/(npxy_in(1)-1);%grid mesh in y
|
---|
| 1428 | dxy(2)=(rangx(2)-rangx(1))/(npxy_in(2)-1);%grid mesh in x
|
---|
| 1429 | else % interpolation grid automatically determined
|
---|
| 1430 | rangx(1)=min(vec_X);
|
---|
| 1431 | rangx(2)=max(vec_X);
|
---|
| 1432 | rangy(2)=min(vec_Y);
|
---|
| 1433 | rangy(1)=max(vec_Y);
|
---|
| 1434 | dxymod=sqrt((rangx(2)-rangx(1))*(rangy(1)-rangy(2))/length(vec_X));
|
---|
| 1435 | dxy=[-dxymod/4 dxymod/4];% increase the resolution 4 times
|
---|
| 1436 | end
|
---|
[869] | 1437 | xi=rangx(1):dxy(2):rangx(2);
|
---|
| 1438 | yi=rangy(1):dxy(1):rangy(2);
|
---|
| 1439 | A=griddata(vec_X,vec_Y,vec_A,xi,yi');
|
---|
[1095] | 1440 | A=reshape(A,length(yi),length(xi));
|
---|
[356] | 1441 | else
|
---|
| 1442 | x=vec_X(1:index(1));% the set of abscissa (obtained on the first line)
|
---|
| 1443 | indexend=index(end);% last vector index of line change
|
---|
| 1444 | ymax=vec_Y(indexend+1);% y coordinate AFTER line change
|
---|
| 1445 | ymin=vec_Y(index(1));
|
---|
| 1446 | y=vec_Y(index);
|
---|
| 1447 | y(length(y)+1)=ymax;
|
---|
| 1448 | nx=length(x); %number of grid points in x
|
---|
| 1449 | ny=length(y); % number of grid points in y
|
---|
| 1450 | B=(reshape(vec_A,nx,ny))'; %vec_A reshaped as a rectangular matrix
|
---|
| 1451 | [X,Y]=meshgrid(x,y);% positions X and Y also reshaped as matrix
|
---|
| 1452 |
|
---|
| 1453 | %linear interpolation to improve the image resolution and/or adjust
|
---|
| 1454 | %to prescribed positions
|
---|
| 1455 | test_interp=1;
|
---|
| 1456 | if exist('rgx_in','var') & ~isempty (rgx_in) & isnumeric(rgx_in) & length(rgx_in)==2% positions imposed from input
|
---|
| 1457 | rangx=rgx_in; % first and last positions
|
---|
| 1458 | rangy=rgy_in;
|
---|
| 1459 | npxy=npxy_in;
|
---|
| 1460 | else
|
---|
| 1461 | rangx=[vec_X(1) vec_X(nx)];% first and last position found for x
|
---|
| 1462 | rangy=[max(ymax,ymin) min(ymax,ymin)];
|
---|
| 1463 | if max(nx,ny) <= 64 & isequal(npxy_in,'np>256')
|
---|
| 1464 | npxy=[8*ny 8*nx];% increase the resolution 8 times
|
---|
| 1465 | elseif max(nx,ny) <= 128 & isequal(npxy_in,'np>256')
|
---|
| 1466 | npxy=[4*ny 4*nx];% increase the resolution 4 times
|
---|
| 1467 | elseif max(nx,ny) <= 256 & isequal(npxy_in,'np>256')
|
---|
| 1468 | npxy=[2*ny 2*nx];% increase the resolution 2 times
|
---|
| 1469 | else
|
---|
| 1470 | npxy=[ny nx];
|
---|
| 1471 | test_interp=0; % no interpolation done
|
---|
| 1472 | end
|
---|
| 1473 | end
|
---|
| 1474 | if test_interp==1%if we interpolate
|
---|
| 1475 | xi=[rangx(1):(rangx(2)-rangx(1))/(npxy(2)-1):rangx(2)];
|
---|
| 1476 | yi=[rangy(1):(rangy(2)-rangy(1))/(npxy(1)-1):rangy(2)];
|
---|
| 1477 | [XI,YI]=meshgrid(xi,yi);
|
---|
| 1478 | A = interp2(X,Y,B,XI,YI);
|
---|
| 1479 | else %no interpolation for a resolution higher than 256
|
---|
| 1480 | A=B;
|
---|
| 1481 | end
|
---|
[801] | 1482 | end
|
---|