[8] | 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:
|
---|
| 6 | % 2D vector fields are represented by arrows, 2D scalar fiedlds by grey scale images or contour plots, 1D fields are represented by usual plot with (abscissa, ordinate).
|
---|
| 7 | % The input field structure is first tested by check_field_structure.m,
|
---|
| 8 | % then split into blocks of related variables by find_field_indices.m.
|
---|
| 9 | % The dimensionality of each block is obtained by this fuction
|
---|
| 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 | %
|
---|
[72] | 14 | % function [PlotType,PlotParamOut,haxes]= plot_field(Data,haxes,PlotParam,htext,PosColorbar)
|
---|
[8] | 15 | %
|
---|
| 16 | % OUPUT:
|
---|
| 17 | % PlotType: type of plot: 'text','line'(curve plot),'plane':2D view,'volume'
|
---|
| 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 | %
|
---|
| 21 | %INPUT
|
---|
| 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
|
---|
[89] | 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 | %
|
---|
[8] | 44 | % additional elements characterizing the projection object (should not be necessary)--
|
---|
| 45 | % Data.Style : style of projection object
|
---|
| 46 | % Data.XObject,.YObject: set of coordinates defining the object position;
|
---|
| 47 | % Data.ProjMode=type of projection ;
|
---|
| 48 | % Data.ProjAngle=angle of projection;
|
---|
| 49 | % Data.DX,.DY,.DZ=increments;
|
---|
| 50 | % Data.MaxY,MinY: min and max Y
|
---|
| 51 |
|
---|
| 52 | % 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.
|
---|
| 53 | %
|
---|
| 54 | % PlotParam: parameters for plotting, as read on the uvmat interface (by function 'read_plot_param.m')
|
---|
[72] | 55 | % .FixedLimits:=0 (default) adjust axes limit to the X,Y data, =1: preserves the previous axes limits
|
---|
| 56 | % .Auto_xy: =0 (default): kepp 1 to 1 aspect ratio for x and y scales, =1: automatic adjustment of the graph
|
---|
[8] | 57 | % --scalars--
|
---|
| 58 | % .Scalar.MaxA: upper bound (saturation color) for the scalar representation, max(field) by default
|
---|
| 59 | % .Scalar.MinA: lower bound (saturation) for the scalar representation, min(field) by default
|
---|
| 60 | % .Scalar.AutoScal: =1 (default) lower and upper bounds of the scalar representation set to the min and max of the field
|
---|
| 61 | % =0 lower and upper bound imposed by .AMax and .MinA
|
---|
| 62 | % .Scalar.BW= 1 black and white representation imposed, =0 by default.
|
---|
| 63 | % .Scalar.Contours= 1: represent scalars by contour plots (Matlab function 'contour'); =0 by default
|
---|
| 64 | % .IncrA : contour interval
|
---|
| 65 | % -- vectors--
|
---|
| 66 | % .Vectors.VecScale: scale for the vector representation
|
---|
| 67 | % .Vectors.AutoVec: =0 (default) automatic length for vector representation, =1: length set by .VecScale
|
---|
| 68 | % .Vectors.HideFalse= 0 (default) false vectors represented in magenta, =1: false vectors not represented;
|
---|
| 69 | % .Vectors.HideWarning= 0 (default) vectors marked by warnflag~=0 marked in black, 1: no warning representation;
|
---|
| 70 | % .Vectors.decimate4 = 0 (default) all vectors reprtesented, =1: half of the vectors represented along each coordinate
|
---|
| 71 | % -- vector color--
|
---|
| 72 | % .Vectors.ColorCode= 'black','white': imposed color (default ='blue')
|
---|
| 73 | % 'rgb', : three colors red, blue, green depending
|
---|
| 74 | % on thresholds .colcode1 and .colcode2 on the input scalar value (C)
|
---|
| 75 | % 'brg': like rgb but reversed color order (blue, green, red)
|
---|
| 76 | % '64 colors': continuous color from blue to red (multijet)
|
---|
| 77 | % .Vectors.colcode1 : first threshold for rgb, first value for'continuous'
|
---|
| 78 | % .Vectors.colcode2 : second threshold for rgb, last value (saturation) for 'continuous'
|
---|
| 79 | % .Vectors.FixedCbounds; =0 (default): the bounds on C representation are min and max, =1: they are fixed by .Minc and .MaxC
|
---|
| 80 | % .Vectors.MinC = imposed minimum of the scalar field used for vector color;
|
---|
| 81 | % .Vectors.MaxC = imposed maximum of the scalar field used for vector color;
|
---|
| 82 | %
|
---|
[72] | 83 | %
|
---|
[8] | 84 | % PosColorbar: if not empty, display a colorbar for B&W images
|
---|
| 85 | % imposed position of the colorbar (ex [0.821 0.471 0.019 0.445])
|
---|
[89] | 86 |
|
---|
[8] | 87 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
---|
| 88 | % Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
|
---|
| 89 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
---|
| 90 | % This file is part of the toolbox UVMAT.
|
---|
| 91 | %
|
---|
| 92 | % UVMAT is free software; you can redistribute it and/or modify
|
---|
| 93 | % it under the terms of the GNU General Public License as published by
|
---|
| 94 | % the Free Software Foundation; either version 2 of the License, or
|
---|
| 95 | % (at your option) any later version.
|
---|
| 96 | %
|
---|
| 97 | % UVMAT is distributed in the hope that it will be useful,
|
---|
| 98 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 99 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 100 | % GNU General Public License (file UVMAT/COPYING.txt) for more details.
|
---|
| 101 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
---|
| 102 |
|
---|
[72] | 103 | function [PlotType,PlotParamOut,haxes]= plot_field(Data,haxes,PlotParam,htext,PosColorbar)
|
---|
| 104 | % TODO:
|
---|
| 105 | % use htext: handles of the text edit box (uicontrol)
|
---|
| 106 | % introduce PlotParam.Hold: 'on' or 'off' (for curves)
|
---|
| 107 |
|
---|
[8] | 108 | %default output
|
---|
| 109 | if ~exist('PlotParam','var'),PlotParam=[];end;
|
---|
[72] | 110 | if ~exist('htext','var'),htext=[];end;
|
---|
[8] | 111 | if ~exist('PosColorbar','var'),PosColorbar=[];end;
|
---|
| 112 | PlotType='text'; %default
|
---|
| 113 | PlotParamOut=PlotParam;%default
|
---|
| 114 |
|
---|
| 115 | % check input structure
|
---|
| 116 | [Data,errormsg]=check_field_structure(Data);
|
---|
| 117 |
|
---|
| 118 | if ~isempty(errormsg)
|
---|
| 119 | msgbox_uvmat('ERROR',['input of plot_field/check_field_structure: ' errormsg])
|
---|
| 120 | display(['input of plot_field/check_field_structure:: ' errormsg])
|
---|
| 121 | return
|
---|
| 122 | end
|
---|
| 123 |
|
---|
| 124 | testnewfig=1;%test to create a new figure (default)
|
---|
| 125 | testzoomaxes=0;%test for the existence of a zoom secondary figure attached to the plotting axes
|
---|
| 126 | if exist('haxes','var')
|
---|
| 127 | if ishandle(haxes)
|
---|
| 128 | if isequal(get(haxes,'Type'),'axes')
|
---|
| 129 | axes(haxes)
|
---|
| 130 | testnewfig=0;
|
---|
| 131 | AxeData=get(haxes,'UserData');
|
---|
| 132 | if isfield(AxeData,'ZoomAxes')&& ishandle(AxeData.ZoomAxes)
|
---|
| 133 | if isequal(get(AxeData.ZoomAxes,'Type'),'axes')
|
---|
| 134 | testzoomaxes=1;
|
---|
| 135 | zoomaxes=AxeData.ZoomAxes;
|
---|
| 136 | end
|
---|
| 137 | end
|
---|
| 138 | end
|
---|
| 139 | end
|
---|
| 140 | end
|
---|
| 141 | if testnewfig% create a new figure and axes if the plotting axes does not exist
|
---|
| 142 | hfig=figure;
|
---|
[89] | 143 | if isfield(Data,'IndexObj') && isfield(Data,'Style') && isfield(Data,'ProjMode')
|
---|
[46] | 144 | figname=[num2str(Data.IndexObj) '-' Data.Style];
|
---|
[8] | 145 | set(hfig,'Name',figname)
|
---|
| 146 | end
|
---|
[89] | 147 | % testhandle=0;
|
---|
| 148 | if isfield(PlotParam,'text_display_1') && ishandle(PlotParam.text_display_1)
|
---|
[8] | 149 | set(hfig,'UserData',PlotParam)
|
---|
[89] | 150 | % testhandle=1;
|
---|
[8] | 151 | end
|
---|
| 152 | set(hfig,'Units','normalized')
|
---|
| 153 | set(hfig,'WindowButtonDownFcn','mouse_down')
|
---|
| 154 | %set(hfig,'WindowButtonMotionFcn',{'mouse_motion',PlotParam})%set mouse action function
|
---|
| 155 | set(hfig,'WindowButtonMotionFcn','mouse_motion')%set mouse action function
|
---|
| 156 | set(hfig,'WindowButtonUpFcn','mouse_up')%set mouse action function
|
---|
| 157 | haxes=axes;
|
---|
| 158 | set(haxes,'position',[0.13,0.2,0.775,0.73])
|
---|
[71] | 159 | else
|
---|
| 160 | hstack=findobj(allchild(0),'Type','figure');%current stack order of figures in matlab
|
---|
[8] | 161 | end
|
---|
[89] | 162 | if isfield(PlotParam,'text_display_1') && ishandle(PlotParam.text_display_1)
|
---|
[8] | 163 | PlotParam=read_plot_param(PlotParam);
|
---|
| 164 | end
|
---|
| 165 | if testnewfig
|
---|
| 166 | PlotParam.NextPlot='add'; %parameter for plot_profile and plot_hist
|
---|
| 167 | end
|
---|
| 168 | if isfield(PlotParam,'Auto_xy') && isequal(PlotParam.Auto_xy,1)
|
---|
| 169 | set(haxes,'DataAspectRatioMode','auto')%automatic aspect ratio
|
---|
| 170 | end
|
---|
| 171 |
|
---|
| 172 | % check the cells of fields :
|
---|
[89] | 173 | % testnbdim=1;
|
---|
[8] | 174 | [CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Data);
|
---|
| 175 |
|
---|
| 176 | if ~isempty(errormsg)
|
---|
| 177 | msgbox_uvmat('ERROR',['input of plot_field/find_field_indices: ' errormsg])
|
---|
| 178 | display(['input of plot_field: ' errormsg])
|
---|
| 179 | return
|
---|
| 180 | end
|
---|
| 181 | if ~isfield(Data,'NbDim') %& ~isfield(Data,'Style')%determine the space dimensionb if not defined: choose the kind of plot
|
---|
[89] | 182 | [Data.NbDim]=max(NbDim);
|
---|
[8] | 183 | end
|
---|
[72] | 184 | if isequal(Data.NbDim,0)
|
---|
| 185 | AxeData=plot_text(Data,htext);
|
---|
[8] | 186 | PlotType='text';
|
---|
| 187 | elseif isequal(Data.NbDim,1)
|
---|
| 188 | [AxeData,haxes]=plot_profile(Data,CellVarIndex,VarType,haxes,PlotParam);%
|
---|
| 189 | if testzoomaxes
|
---|
| 190 | [AxeData,zoomaxes,PlotParamOut]=plot_profile(Data,CellVarIndex,VarType,zoomaxes,PlotParam);
|
---|
| 191 | AxeData.ZoomAxes=zoomaxes;
|
---|
| 192 | end
|
---|
| 193 | PlotType='line';
|
---|
| 194 | elseif isequal(Data.NbDim,2)
|
---|
| 195 | ind_select=find(NbDim>=2);
|
---|
| 196 | if numel(ind_select)>2
|
---|
[85] | 197 | msgbox_uvmat('ERROR','more than two fields to map')
|
---|
| 198 | display('more than two fields to map')
|
---|
[8] | 199 | return
|
---|
| 200 | end
|
---|
[72] | 201 | [AxeData,haxes,PlotParamOut,PlotType]=plot_plane(Data,CellVarIndex(ind_select),VarType(ind_select),haxes,PlotParam,htext,PosColorbar);
|
---|
[8] | 202 | if testzoomaxes
|
---|
| 203 | [AxeData,zoomaxes,PlotParamOut]=plot_plane(Data,CellVarIndex(ind_select),VarType(ind_select),zoomaxes,PlotParam,1,PosColorbar);
|
---|
| 204 | AxeData.ZoomAxes=zoomaxes;
|
---|
| 205 | end
|
---|
| 206 | elseif isequal(Data.NbDim,3)
|
---|
| 207 | msgbox_uvmat('ERROR','volume plot not implemented yet')
|
---|
| 208 | return
|
---|
[89] | 209 | % else
|
---|
| 210 | % testnbdim=0;
|
---|
[8] | 211 | end
|
---|
| 212 |
|
---|
| 213 | %display (or delete) error message
|
---|
| 214 | htext=findobj(haxes,'Tag','hTxt');
|
---|
| 215 | if isfield(Data,'Txt')
|
---|
| 216 | if isempty(htext)
|
---|
| 217 | Xlim=get(haxes,'XLim');
|
---|
| 218 | Ylim=get(haxes,'YLim');
|
---|
| 219 | htext=text(Xlim(1),(Ylim(1)+Ylim(2))/2,Data.Txt,'Tag','hTxt','Color','r');
|
---|
| 220 | set(htext,'Interpreter','none')
|
---|
| 221 | else
|
---|
| 222 | set(htext,'String',Data.Txt)
|
---|
| 223 | end
|
---|
| 224 | elseif ~isempty(htext)
|
---|
| 225 | delete(htext)
|
---|
| 226 | end
|
---|
| 227 |
|
---|
| 228 | % set graph aspect ratio
|
---|
| 229 |
|
---|
| 230 |
|
---|
| 231 | set(haxes,'UserData',AxeData)
|
---|
[71] | 232 | if ~testnewfig
|
---|
| 233 | set(0,'Children',hstack);%put back the initial figure stack after plot creation
|
---|
[8] | 234 | %set(haxes,'Tag','uvmat');
|
---|
[71] | 235 | end
|
---|
[8] | 236 |
|
---|
| 237 |
|
---|
[72] | 238 | %-------------------------------------------------------------------
|
---|
| 239 | function hdisplay=plot_text(FieldData,hdisplay_in)
|
---|
| 240 | %-------------------------------------------------------------------
|
---|
[89] | 241 | if exist('hdisplay_in','var') && ishandle(hdisplay_in) && isequal(get(hdisplay_in,'Type'),'uicontrol')
|
---|
[72] | 242 | hdisplay=hdisplay_in;
|
---|
| 243 | else
|
---|
| 244 | figure;%create new figure
|
---|
| 245 | hdisplay=uicontrol('Style','edit', 'Units','normalized','Position', [0 0 1 1],'Max',2,'FontName','monospaced');
|
---|
| 246 | end
|
---|
| 247 |
|
---|
| 248 | ff=fields(FieldData);%list of field names
|
---|
| 249 | vv=struct2cell(FieldData);%list of field values
|
---|
| 250 |
|
---|
| 251 | for icell=1:length(vv)
|
---|
| 252 | Tabcell{icell,1}=ff{icell};
|
---|
| 253 | ss=vv{icell};
|
---|
| 254 | sizss=size(ss);
|
---|
| 255 | if isnumeric(ss)
|
---|
[89] | 256 | if sizss(1)<=1 && length(ss)<5
|
---|
[72] | 257 | displ{icell}=num2str(ss);
|
---|
| 258 | else
|
---|
| 259 | displ{icell}=[class(ss) ', size ' num2str(size(ss))];
|
---|
| 260 | end
|
---|
| 261 | elseif ischar(ss)
|
---|
| 262 | displ{icell}=ss;
|
---|
| 263 | elseif iscell(ss)
|
---|
| 264 | sizcell=size(ss);
|
---|
[89] | 265 | if sizcell(1)==1 && length(sizcell)==2 %line cell
|
---|
[72] | 266 | ssline='{''';
|
---|
| 267 | for icolumn=1:sizcell(2)
|
---|
| 268 | if isnumeric(ss{icolumn})
|
---|
[89] | 269 | if size(ss{icolumn},1)<=1 && length(ss{icolumn})<5
|
---|
[72] | 270 | sscolumn=num2str(ss{icolumn});%line vector
|
---|
| 271 | else
|
---|
| 272 | sscolumn=[class(ss{icolumn}) ', size ' num2str(size(ss{icolumn}))];
|
---|
| 273 | end
|
---|
| 274 | elseif ischar(ss{icolumn})
|
---|
| 275 | sscolumn=ss{icolumn};
|
---|
| 276 | else
|
---|
| 277 | sscolumn=class(ss{icolumn});
|
---|
| 278 | end
|
---|
| 279 | if icolumn==1
|
---|
| 280 | ssline=[ssline sscolumn];
|
---|
| 281 | else
|
---|
| 282 | ssline=[ssline ''',''' sscolumn];
|
---|
| 283 | end
|
---|
| 284 | end
|
---|
| 285 | displ{icell}=[ssline '''}'];
|
---|
| 286 | else
|
---|
| 287 | displ{icell}=[class(ss) ', size ' num2str(sizcell)];
|
---|
| 288 | end
|
---|
| 289 | else
|
---|
| 290 | displ{icell}=class(ss);
|
---|
| 291 | end
|
---|
| 292 | Tabcell{icell,2}=displ{icell};
|
---|
| 293 | end
|
---|
| 294 | Tabchar=cell2tab(Tabcell,': ');
|
---|
| 295 | set(hdisplay,'String', Tabchar)
|
---|
| 296 |
|
---|
| 297 |
|
---|
| 298 | %-------------------------------------------------------------------
|
---|
[8] | 299 | function [AxeData,haxes]=plot_profile(data,CellVarIndex,VarType,haxes,PlotParam)
|
---|
[72] | 300 | %-------------------------------------------------------------------
|
---|
[61] | 301 | %axes(haxes)
|
---|
[8] | 302 | hfig=get(haxes,'parent');
|
---|
| 303 | AxeData=data;
|
---|
[71] | 304 |
|
---|
[8] | 305 | ColorOrder=[1 0 0;0 0.5 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];
|
---|
| 306 | set(haxes,'ColorOrder',ColorOrder)
|
---|
| 307 | if isfield(PlotParam,'NextPlot')
|
---|
| 308 | set(haxes,'NextPlot',PlotParam.NextPlot)
|
---|
| 309 | end
|
---|
[72] | 310 | % adjust the size of the plot to include the whole field,
|
---|
[61] | 311 | if isfield(PlotParam,'FixedLimits') && isequal(PlotParam.FixedLimits,1) %adjust the graph limits*
|
---|
| 312 | set(haxes,'XLimMode', 'manual')
|
---|
| 313 | set(haxes,'YLimMode', 'manual')
|
---|
| 314 | else
|
---|
| 315 | set(haxes,'XLimMode', 'auto')
|
---|
| 316 | set(haxes,'YLimMode', 'auto')
|
---|
| 317 | end
|
---|
[8] | 318 | legend_str={};
|
---|
| 319 |
|
---|
| 320 | %initiates string of the plot command
|
---|
[71] | 321 | plotstr='hhh=plot(';
|
---|
[8] | 322 | textmean={};
|
---|
[89] | 323 | % abscissa_name='';
|
---|
[8] | 324 | coord_x_index=[];
|
---|
[71] | 325 | test_newplot=1;
|
---|
[80] | 326 | hh=findobj(haxes,'tag','plot_line');
|
---|
[89] | 327 | % num_curve=numel(hh);
|
---|
[80] | 328 | icurve=0;
|
---|
[8] | 329 | for icell=1:length(CellVarIndex)
|
---|
| 330 | testfalse=0;
|
---|
| 331 | VarIndex=CellVarIndex{icell};% indices of the selected variables in the list data.ListVarName
|
---|
| 332 | DimCell=data.VarDimName{VarIndex(1)};
|
---|
| 333 | if ischar(DimCell)
|
---|
| 334 | DimCell={DimCell};
|
---|
| 335 | end
|
---|
| 336 | XName=DimCell{1}; %first dimension considered as abscissa
|
---|
| 337 | if ~isempty(VarType{icell}.coord_x)
|
---|
| 338 | coord_x_index=VarType{icell}.coord_x;
|
---|
| 339 | else
|
---|
| 340 | coord_x_index_cell=VarType{icell}.coord(1);
|
---|
| 341 | if isequal(coord_x_index_cell,0)
|
---|
| 342 | continue % the cell has no abscissa, skip it
|
---|
| 343 | end
|
---|
| 344 | if ~isempty(coord_x_index)&&~isequal(coord_x_index_cell,coord_x_index)
|
---|
| 345 | continue %all the selected variables must have the same first dimension
|
---|
| 346 | else
|
---|
| 347 | coord_x_index=coord_x_index_cell;
|
---|
| 348 | end
|
---|
| 349 | end
|
---|
| 350 | testplot=ones(size(data.ListVarName));%default test for plotted variables
|
---|
| 351 | testcoordvar=0;
|
---|
| 352 | charplot_0='''-''';%default
|
---|
[89] | 353 | if isfield(data,'ObjectProjMode')&& isequal(data.ObjectProjMode,'projection')
|
---|
[71] | 354 | charplot_0='+';
|
---|
[8] | 355 | end
|
---|
| 356 | xtitle='';
|
---|
| 357 |
|
---|
| 358 | xtitle=data.ListVarName{coord_x_index};
|
---|
| 359 | eval(['coord_x{icell}=data.' data.ListVarName{coord_x_index} ';']);%coordinate variable set as coord_x
|
---|
| 360 | if isfield(data,'VarAttribute')&& numel(data.VarAttribute)>=coord_x_index && isfield(data.VarAttribute{coord_x_index},'units')
|
---|
| 361 | xtitle=[xtitle '(' data.VarAttribute{coord_x_index}.units ')'];
|
---|
| 362 | end
|
---|
| 363 | eval(['coord_x{icell}=data.' data.ListVarName{coord_x_index} ';']);%coordinate variable set as coord_x
|
---|
| 364 | testcoordvar=1;
|
---|
| 365 | testplot(coord_x_index)=0;
|
---|
| 366 | if ~isempty(VarType{icell}.ancillary')
|
---|
| 367 | testplot(VarType{icell}.ancillary)=0;
|
---|
| 368 | end
|
---|
| 369 | if ~isempty(VarType{icell}.warnflag')
|
---|
| 370 | testplot(VarType{icell}.warnflag)=0;
|
---|
| 371 | end
|
---|
[71] | 372 |
|
---|
[8] | 373 | if isfield(data,'VarAttribute')
|
---|
| 374 | VarAttribute=data.VarAttribute;
|
---|
| 375 | for ivar=1:length(VarIndex)
|
---|
[89] | 376 | if length(VarAttribute)>=VarIndex(ivar) && isfield(VarAttribute{VarIndex(ivar)},'long_name')
|
---|
[8] | 377 | plotname{VarIndex(ivar)}=VarAttribute{VarIndex(ivar)}.long_name;
|
---|
| 378 | else
|
---|
| 379 | plotname{VarIndex(ivar)}=data.ListVarName{VarIndex(ivar)};%name for display in plot A METTRE
|
---|
| 380 | end
|
---|
| 381 | end
|
---|
[80] | 382 | end
|
---|
| 383 | % test_newplot=0;%default
|
---|
| 384 | % if num_curve>=icurve+numel(find(testplot(VarIndex)))%update existing curves
|
---|
| 385 | % if ~isempty(VarType{icell}.discrete')
|
---|
| 386 | % charplot_0='+';
|
---|
| 387 | % LineStyle='none';
|
---|
| 388 | % else
|
---|
| 389 | % charplot_0='none';
|
---|
| 390 | % LineStyle='-';
|
---|
| 391 | % end
|
---|
| 392 | % for ivar=1:length(VarIndex)
|
---|
| 393 | % if testplot(VarIndex(ivar))
|
---|
| 394 | % icurve=icurve+1;
|
---|
| 395 | % VarName=data.ListVarName{VarIndex(ivar)};
|
---|
| 396 | % eval(['data.' VarName '=squeeze(data.' VarName ');'])
|
---|
| 397 | % set(hh(icurve),'LineStyle',LineStyle)
|
---|
| 398 | % set(hh(icurve),'Marker',charplot_0)
|
---|
| 399 | % set(hh(icurve),'XData',coord_x{icell})
|
---|
| 400 | % eval(['yy=data.' VarName ';'])
|
---|
| 401 | % set(hh(icurve),'YData',yy);
|
---|
| 402 | % end
|
---|
| 403 | % end
|
---|
| 404 | % else% new plot
|
---|
[71] | 405 | if ~isempty(VarType{icell}.discrete')
|
---|
| 406 | charplot_0='''+''';
|
---|
| 407 | else
|
---|
| 408 | charplot_0='''-''';
|
---|
| 409 | end
|
---|
| 410 | for ivar=1:length(VarIndex)
|
---|
| 411 | if testplot(VarIndex(ivar))
|
---|
| 412 | VarName=data.ListVarName{VarIndex(ivar)};
|
---|
| 413 | eval(['data.' VarName '=squeeze(data.' VarName ');'])
|
---|
| 414 | % if isequal(VarName,'A')
|
---|
| 415 | % charplot='''-''';
|
---|
| 416 | % else
|
---|
| 417 | % charplot=charplot_0;
|
---|
| 418 | % end
|
---|
| 419 | plotstr=[plotstr 'coord_x{' num2str(icell) '},data.' VarName ',' charplot_0 ','];
|
---|
| 420 | eval(['nbcomponent2=size(data.' VarName ',2);']);
|
---|
| 421 | eval(['nbcomponent1=size(data.' VarName ',1);']);
|
---|
| 422 | if numel(coord_x{icell})==2
|
---|
| 423 | coord_x{icell}=linspace(coord_x{icell}(1),coord_x{icell}(2),nbcomponent1);
|
---|
| 424 | end
|
---|
| 425 | eval(['varmean=mean(double(data.' VarName '));']);%mean value
|
---|
| 426 | textmean=[textmean; {[VarName 'mean= ' num2str(varmean,4)]}];
|
---|
| 427 | if nbcomponent1==1| nbcomponent2==1
|
---|
| 428 | legend_str=[legend_str {VarName}]; %variable with one component
|
---|
| 429 | else %variable with severals components
|
---|
| 430 | for ic=1:min(nbcomponent1,nbcomponent2)
|
---|
| 431 | legend_str=[legend_str [VarName '_' num2str(ic)]]; %variable with severals components
|
---|
| 432 | end % labeled by their index (e.g. color component)
|
---|
| 433 | end
|
---|
[8] | 434 | end
|
---|
| 435 | end
|
---|
[80] | 436 | % end
|
---|
[8] | 437 | end
|
---|
[75] | 438 | if test_newplot && ~isequal(plotstr,'hhh=plot(')
|
---|
[80] | 439 | plotstr=[plotstr '''tag'',''plot_line'');'];
|
---|
[71] | 440 | %execute plot (instruction plotstr)
|
---|
[8] | 441 | eval(plotstr)
|
---|
[71] | 442 |
|
---|
[8] | 443 | %%%%%
|
---|
[71] | 444 | grid(haxes, 'on')
|
---|
[8] | 445 | hxlabel=xlabel(xtitle);
|
---|
| 446 | set(hxlabel,'Interpreter','none')% desable tex interpreter
|
---|
| 447 | if length(legend_str)>=1
|
---|
| 448 | hylabel=ylabel(legend_str{end});
|
---|
| 449 | set(hylabel,'Interpreter','none')% desable tex interpreter
|
---|
| 450 | end
|
---|
| 451 | if ~isempty(legend_str)
|
---|
| 452 | hlegend=findobj(hfig,'Tag','legend');
|
---|
| 453 | if isempty(hlegend)
|
---|
| 454 | hlegend=legend(legend_str);
|
---|
| 455 | txt=ver;
|
---|
| 456 | Release=txt(1).Release;
|
---|
| 457 | relnumb=str2num(Release(3:4));
|
---|
| 458 | if relnumb >= 14
|
---|
| 459 | set(hlegend,'Interpreter','none')% desable tex interpreter
|
---|
| 460 | end
|
---|
| 461 | else
|
---|
| 462 | legend_old=get(hlegend,'String');
|
---|
[89] | 463 | if isequal(size(legend_old,1),size(legend_str,1))&&~isequal(legend_old,legend_str)
|
---|
[8] | 464 | set(hlegend,'String',[legend_old legend_str]);
|
---|
| 465 | end
|
---|
| 466 | end
|
---|
| 467 | end
|
---|
| 468 | title_str='';
|
---|
| 469 | if isfield(data,'filename')
|
---|
| 470 | [Path, title_str, ext]=fileparts(data.filename);
|
---|
| 471 | title_str=[title_str ext];
|
---|
| 472 | end
|
---|
| 473 | if isfield(data,'Action')
|
---|
| 474 | if ~isequal(title_str,'')
|
---|
| 475 | title_str=[title_str ', '];
|
---|
| 476 | end
|
---|
| 477 | title_str=[title_str data.Action];
|
---|
| 478 | end
|
---|
| 479 | htitle=title(title_str);
|
---|
| 480 | txt=ver;
|
---|
| 481 | Release=txt(1).Release;
|
---|
| 482 | relnumb=str2num(Release(3:4));
|
---|
| 483 | if relnumb >= 14
|
---|
| 484 | set(htitle,'Interpreter','none')% desable tex interpreter
|
---|
| 485 | end
|
---|
| 486 | % A REPRENDRE Mean
|
---|
| 487 | % hlist=findobj(gcf,'Style','listbox','Tag','liststat');
|
---|
| 488 | % if isempty(hlist)
|
---|
| 489 | % 'text'
|
---|
| 490 | % textmean
|
---|
| 491 | % set(gca,'position',[0.13,0.2,0.775,0.73])
|
---|
| 492 | % uicontrol('Style','popupmenu','Position',[20 20 200 20],'String',textmean,'Tag','liststat');
|
---|
| 493 | % else
|
---|
| 494 | % set(hlist(1),'String',textmean)
|
---|
| 495 | % end
|
---|
| 496 | end
|
---|
| 497 |
|
---|
| 498 |
|
---|
[72] | 499 | %-------------------------------------------------------------------
|
---|
| 500 | function [AxeData,haxes,PlotParamOut,PlotType]=plot_plane(Data,CellVarIndex,VarTypeCell,haxes,PlotParam,htext,PosColorbar)
|
---|
| 501 | %-------------------------------------------------------------------
|
---|
[71] | 502 | grid(haxes, 'off')
|
---|
[8] | 503 | %default plotting parameters
|
---|
| 504 | PlotType='plane';%default
|
---|
| 505 | if ~exist('PlotParam','var')
|
---|
| 506 | PlotParam=[];
|
---|
| 507 | end
|
---|
| 508 | if ~isfield(PlotParam,'Scalar')
|
---|
| 509 | PlotParam.Scalar=[];
|
---|
| 510 | end
|
---|
| 511 | if ~isfield(PlotParam,'Vectors')
|
---|
| 512 | PlotParam.Vectors=[];
|
---|
| 513 | end
|
---|
| 514 | PlotParamOut=PlotParam;%default
|
---|
| 515 |
|
---|
| 516 | %plotting axes
|
---|
| 517 | hfig=get(haxes,'parent');
|
---|
| 518 | hcol=findobj(hfig,'Tag','Colorbar'); %look for colorbar axes
|
---|
| 519 | hima=findobj(haxes,'Tag','ima');% search existing image in the current axes
|
---|
| 520 | AxeData=get(haxes,'UserData'); %default
|
---|
| 521 | if ~isstruct(AxeData)% AxeData must be a structure
|
---|
| 522 | AxeData=[];
|
---|
| 523 | end
|
---|
| 524 | AxeData.NbDim=2;
|
---|
| 525 | if isfield(Data,'ObjectCoord')
|
---|
| 526 | AxeData.ObjectCoord=Data.ObjectCoord;
|
---|
| 527 | end
|
---|
| 528 |
|
---|
| 529 | test_ima=0; %default: test for image or map plot
|
---|
| 530 | test_vec=0; %default: test for vector plots
|
---|
| 531 | test_black=0;
|
---|
| 532 | test_false=0;
|
---|
| 533 | test_C=0;
|
---|
| 534 | XName='';
|
---|
| 535 | x_units='';
|
---|
| 536 | YName='';
|
---|
| 537 | y_units='';
|
---|
| 538 | for icell=1:length(CellVarIndex) % length(CellVarIndex) =1 or 2 (from the calling function)
|
---|
| 539 | VarType=VarTypeCell{icell};
|
---|
| 540 | ivar_X=VarType.coord_x; % defines (unique) index for the variable representing unstructured x coordinate (default =[])
|
---|
| 541 | ivar_Y=VarType.coord_y; % defines (unique)index for the variable representing unstructured y coordinate (default =[])
|
---|
| 542 | ivar_U=VarType.vector_x; % defines (unique) index for the variable representing x vector component (default =[])
|
---|
| 543 | ivar_V=VarType.vector_y; % defines (unique) index for the variable representing y vector component (default =[])
|
---|
| 544 | ivar_C=[VarType.scalar VarType.image VarType.color VarType.ancillary]; %defines index (indices) for the scalar or ancillary fields
|
---|
| 545 | if numel(ivar_C)>1
|
---|
| 546 | msgbox_uvmat('ERROR','error in plot_field: too many scalar inputs')
|
---|
| 547 | return
|
---|
| 548 | end
|
---|
| 549 | ivar_F=VarType.warnflag; %defines index (unique) for warning flag variable
|
---|
| 550 | ivar_FF=VarType.errorflag; %defines index (unique) for error flag variable
|
---|
| 551 | ind_coord=find(VarType.coord);
|
---|
| 552 | if numel(ind_coord)==2
|
---|
| 553 | VarType.coord=VarType.coord(ind_coord);
|
---|
| 554 | end
|
---|
| 555 | idim_Y=[];
|
---|
| 556 | test_grid=0;
|
---|
| 557 | if ~isempty(ivar_U) && ~isempty(ivar_V)% vector components detected
|
---|
| 558 | if test_vec
|
---|
| 559 | msgbox_uvmat('ERROR','error in plot_field: attempt to plot two vector fields')
|
---|
| 560 | return
|
---|
| 561 | else
|
---|
| 562 | test_vec=1;
|
---|
| 563 | eval(['vec_U=Data.' Data.ListVarName{ivar_U} ';'])
|
---|
| 564 | eval(['vec_V=Data.' Data.ListVarName{ivar_V} ';'])
|
---|
[89] | 565 | 'TESTplot'
|
---|
| 566 | VarType.coord
|
---|
[8] | 567 | if ~isempty(ivar_X) && ~isempty(ivar_Y)% 2D field (with unstructured coordinates or structured ones (then ivar_X and ivar_Y empty)
|
---|
| 568 | eval(['vec_X=Data.' Data.ListVarName{ivar_X} ';'])
|
---|
| 569 | eval(['vec_Y=Data.' Data.ListVarName{ivar_Y} ';'])
|
---|
| 570 | elseif numel(VarType.coord)==2 & VarType.coord~=[0 0];%coordinates defines by dimension variables
|
---|
| 571 | eval(['y=Data.' Data.ListVarName{VarType.coord(1)} ';'])
|
---|
| 572 | eval(['x=Data.' Data.ListVarName{VarType.coord(2)} ';'])
|
---|
| 573 | if numel(y)==2 % y defined by first and last values on aregular mesh
|
---|
| 574 | y=linspace(y(1),y(2),size(vec_U,1));
|
---|
| 575 | end
|
---|
| 576 | if numel(x)==2 % y defined by first and last values on aregular mesh
|
---|
| 577 | x=linspace(x(1),x(2),size(vec_U,2));
|
---|
| 578 | end
|
---|
| 579 | [vec_X,vec_Y]=meshgrid(x,y);
|
---|
| 580 | else
|
---|
| 581 | msgbox_uvmat('ERROR','error in plot_field: invalid coordinate definition for vector field')
|
---|
| 582 | return
|
---|
| 583 | end
|
---|
| 584 | if ~isempty(ivar_C)
|
---|
| 585 | eval(['vec_C=Data.' Data.ListVarName{ivar_C} ';']) ;
|
---|
| 586 | vec_C=reshape(vec_C,1,numel(vec_C));
|
---|
| 587 | test_C=1;
|
---|
| 588 | end
|
---|
| 589 | if ~isempty(ivar_F)%~(isfield(PlotParam.Vectors,'HideWarning')&& isequal(PlotParam.Vectors.HideWarning,1))
|
---|
| 590 | if test_vec
|
---|
| 591 | eval(['vec_F=Data.' Data.ListVarName{ivar_F} ';']) % warning flags for dubious vectors
|
---|
| 592 | if ~(isfield(PlotParam.Vectors,'HideWarning') && isequal(PlotParam.Vectors.HideWarning,1))
|
---|
| 593 | test_black=1;
|
---|
| 594 | end
|
---|
| 595 | end
|
---|
| 596 | end
|
---|
| 597 | if ~isempty(ivar_FF) %&& ~test_false
|
---|
| 598 | if test_vec% TODO: deal with FF for structured coordinates
|
---|
| 599 | eval(['vec_FF=Data.' Data.ListVarName{ivar_FF} ';']) % flags for false vectors
|
---|
| 600 | end
|
---|
| 601 | end
|
---|
| 602 | end
|
---|
| 603 | elseif ~isempty(ivar_C) %scalar or image
|
---|
| 604 | if test_ima
|
---|
| 605 | msgbox_uvmat('ERROR','attempt to plot two scalar fields or images')
|
---|
| 606 | return
|
---|
| 607 | end
|
---|
| 608 | eval(['A=squeeze(Data.' Data.ListVarName{ivar_C} ');']) ;% scalar represented as color image
|
---|
| 609 | test_ima=1;
|
---|
| 610 | if ~isempty(ivar_X) && ~isempty(ivar_Y)% 2D field (with unstructured coordinates or structured ones (then ivar_X and ivar_Y empty)
|
---|
| 611 | XName=Data.ListVarName{ivar_X};
|
---|
| 612 | YName=Data.ListVarName{ivar_Y};
|
---|
| 613 | eval(['AX=Data.' XName ';'])
|
---|
| 614 | eval(['AY=Data.' YName ';'])
|
---|
| 615 | [A,AX,AY]=proj_grid(AX',AY',A',[],[],'np>256'); % interpolate on a grid
|
---|
| 616 | if isfield(Data,'VarAttribute')
|
---|
[89] | 617 | if numel(Data.VarAttribute)>=ivar_X && isfield(Data.VarAttribute{ivar_X},'units')
|
---|
[8] | 618 | x_units=['(' Data.VarAttribute{ivar_X}.units ')'];
|
---|
| 619 | end
|
---|
[89] | 620 | if numel(Data.VarAttribute)>=ivar_Y && isfield(Data.VarAttribute{ivar_Y},'units')
|
---|
[8] | 621 | y_units=['(' Data.VarAttribute{ivar_Y}.units ')'];
|
---|
| 622 | end
|
---|
| 623 | end
|
---|
| 624 | elseif numel(VarType.coord)==2 %structured coordinates
|
---|
| 625 | XName=Data.ListVarName{VarType.coord(2)};
|
---|
| 626 | YName=Data.ListVarName{VarType.coord(1)};
|
---|
| 627 | eval(['AY=Data.' Data.ListVarName{VarType.coord(1)} ';'])
|
---|
| 628 | eval(['AX=Data.' Data.ListVarName{VarType.coord(2)} ';'])
|
---|
| 629 | test_interp_X=0; %default, regularly meshed X coordinate
|
---|
| 630 | test_interp_Y=0; %default, regularly meshed Y coordinate
|
---|
| 631 | if isfield(Data,'VarAttribute')
|
---|
[89] | 632 | if numel(Data.VarAttribute)>=VarType.coord(2) && isfield(Data.VarAttribute{VarType.coord(2)},'units')
|
---|
[8] | 633 | x_units=['(' Data.VarAttribute{VarType.coord(2)}.units ')'];
|
---|
| 634 | end
|
---|
| 635 | if numel(Data.VarAttribute)>=VarType.coord(1) & isfield(Data.VarAttribute{VarType.coord(1)},'units')
|
---|
| 636 | y_units=['(' Data.VarAttribute{VarType.coord(1)}.units ')'];
|
---|
| 637 | end
|
---|
| 638 | end
|
---|
| 639 | if numel(AY)>2
|
---|
| 640 | DAY=diff(AY);
|
---|
| 641 | DAY_min=min(DAY);
|
---|
| 642 | DAY_max=max(DAY);
|
---|
| 643 | if sign(DAY_min)~=sign(DAY_max);% =1 for increasing values, 0 otherwise
|
---|
| 644 | errormsg=['errror in plot_field.m: non monotonic dimension variable # ' ListVarName{VarType.coord(1)} ];
|
---|
| 645 | return
|
---|
| 646 | end
|
---|
| 647 | test_interp_Y=(DAY_max-DAY_min)> 0.0001*abs(DAY_max);
|
---|
| 648 | end
|
---|
| 649 | if numel(AX)>2
|
---|
| 650 | DAX=diff(AX);
|
---|
| 651 | DAX_min=min(DAX);
|
---|
| 652 | DAX_max=max(DAX);
|
---|
| 653 | if sign(DAX_min)~=sign(DAX_max);% =1 for increasing values, 0 otherwise
|
---|
| 654 | errormsg=['errror in plot_field.m: non monotonic dimension variable # ' ListVarName{VarType.coord(2)} ];
|
---|
| 655 | return
|
---|
| 656 | end
|
---|
| 657 | test_interp_X=(DAX_max-DAX_min)> 0.0001*abs(DAX_max);
|
---|
| 658 | end
|
---|
| 659 | if test_interp_Y
|
---|
| 660 | npxy(1)=max([256 floor((AY(end)-AY(1))/DAY_min) floor((AY(end)-AY(1))/DAY_max)]);
|
---|
| 661 | yI=linspace(AY(1),AY(end),npxy(1));
|
---|
| 662 | if ~test_interp_X
|
---|
| 663 | xI=linspace(AX(1),AX(end),size(A,2));%default
|
---|
| 664 | AX=xI;
|
---|
| 665 | end
|
---|
| 666 | end
|
---|
| 667 | if test_interp_X
|
---|
| 668 | npxy(1)=max([256 floor((AX(end)-AX(1))/DAX_min) floor((AX(end)-AX(1))/DAX_max)]);
|
---|
| 669 | xI=linspace(AX(1),AX(end),npxy(2));
|
---|
| 670 | if ~test_interp_Y
|
---|
| 671 | yI=linspace(AY(1),AY(end),size(A,1));
|
---|
| 672 | AY=yI;
|
---|
| 673 | end
|
---|
| 674 | end
|
---|
| 675 | if test_interp_X || test_interp_Y
|
---|
| 676 | [AX2D,AY2D]=meshgrid(AX,AY);
|
---|
| 677 | A=interp2(AX2D,AY2D,double(A),xI,yI');
|
---|
| 678 | end
|
---|
| 679 | AX=[AX(1) AX(end)];% keep only the lower and upper bounds for image represnetation
|
---|
| 680 | AY=[AY(1) AY(end)];
|
---|
| 681 | else
|
---|
| 682 | msgbox_uvmat('ERROR','error in plot_field: invalid coordinate definition ')
|
---|
| 683 | return
|
---|
| 684 | end
|
---|
| 685 | x_label=[Data.ListVarName{ivar_X} '(' x_units ')'];
|
---|
| 686 | end
|
---|
| 687 | % if isfield(Data,'VarAttribute')
|
---|
| 688 | % VarAttribute=Data.VarAttribute;
|
---|
| 689 | % end
|
---|
| 690 | end
|
---|
| 691 |
|
---|
| 692 | %%%%%%%%%%%%%%%%%%%%% image or scalar plot %%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
| 693 |
|
---|
| 694 | if ~isfield(PlotParam.Scalar,'Contours')
|
---|
| 695 | PlotParam.Scalar.Contours=0; %default
|
---|
| 696 | end
|
---|
| 697 | PlotParamOut=PlotParam; %default
|
---|
| 698 | if test_ima
|
---|
| 699 | % distinguish B/W and color images
|
---|
| 700 | np=size(A);%size of image
|
---|
[88] | 701 | siz=numel(np);
|
---|
| 702 | if siz>3
|
---|
| 703 | msgbox_uvmat('ERROR','unrecognized scalar type ')
|
---|
| 704 | return
|
---|
| 705 | end
|
---|
| 706 | if siz==3
|
---|
| 707 | if np(3)==1
|
---|
| 708 | siz=2;%B W image
|
---|
| 709 | elseif np(3)==3
|
---|
| 710 | siz=3;%color image
|
---|
| 711 | else
|
---|
| 712 | msgbox_uvmat('ERROR',['unrecognized scalar type: ' num2str(np(3)) ' color components'])
|
---|
| 713 | return
|
---|
| 714 | end
|
---|
| 715 | end
|
---|
[8] | 716 | %set the color map
|
---|
[89] | 717 | if isfield(PlotParam.Scalar,'BW')
|
---|
| 718 | BW=PlotParam.Scalar.BW; %test for BW gray scale images
|
---|
| 719 | else
|
---|
| 720 | BW=(siz==2) && (isa(A,'uint8')|| isa(A,'uint16'));% non color images represented in gray scale by default
|
---|
| 721 | end
|
---|
[88] | 722 | if siz==2 %for black and white images
|
---|
[8] | 723 | if ~isfield(PlotParam.Scalar,'AutoScal')
|
---|
| 724 | PlotParam.Scalar.AutoScal=0;%default
|
---|
| 725 | end
|
---|
| 726 | if ~isfield(PlotParam.Scalar,'MinA')
|
---|
| 727 | PlotParam.Scalar.MinA=[];%default
|
---|
| 728 | end
|
---|
| 729 | if ~isfield(PlotParam.Scalar,'MaxA')
|
---|
| 730 | PlotParam.Scalar.MaxA=[];%default
|
---|
| 731 | end
|
---|
| 732 | if isequal(PlotParam.Scalar.AutoScal,0)|isempty(PlotParam.Scalar.MinA)|~isa(PlotParam.Scalar.MinA,'double') %correct if there is no numerical data in edit box
|
---|
| 733 | MinA=double(min(min(A)));
|
---|
| 734 | else
|
---|
| 735 | MinA=PlotParam.Scalar.MinA;
|
---|
| 736 | end;
|
---|
[89] | 737 | if isequal(PlotParam.Scalar.AutoScal,0)||isempty(PlotParam.Scalar.MaxA)||~isa(PlotParam.Scalar.MaxA,'double') %correct if there is no numerical data in edit box
|
---|
[8] | 738 | MaxA=double(max(max(A)));
|
---|
| 739 | else
|
---|
| 740 | MaxA=PlotParam.Scalar.MaxA;
|
---|
| 741 | end;
|
---|
| 742 | PlotParamOut.Scalar.MinA=MinA;
|
---|
| 743 | PlotParamOut.Scalar.MaxA=MaxA;
|
---|
| 744 | axes(haxes)
|
---|
| 745 | if isequal(PlotParam.Scalar.Contours,1)
|
---|
| 746 | if ~isempty(hima) & ishandle(hima)
|
---|
| 747 | delete(hima)
|
---|
| 748 | end
|
---|
| 749 | if ~isfield(PlotParam.Scalar,'IncrA')
|
---|
| 750 | PlotParam.Scalar.IncrA=[];
|
---|
| 751 | end
|
---|
| 752 | if isempty(PlotParam.Scalar.IncrA)% | PlotParam.Scalar.AutoScal==0
|
---|
| 753 | cont=colbartick(MinA,MaxA);
|
---|
| 754 | intercont=cont(2)-cont(1);%default
|
---|
| 755 | PlotParamOut.Scalar.IncrA=intercont;
|
---|
| 756 | else
|
---|
| 757 | intercont=PlotParam.Scalar.IncrA;
|
---|
| 758 | end
|
---|
| 759 | B=A;
|
---|
| 760 | abscontmin=intercont*floor(MinA/intercont);
|
---|
| 761 | abscontmax=intercont*ceil(MaxA/intercont);
|
---|
| 762 | contmin=intercont*floor(min(min(B))/intercont);
|
---|
| 763 | contmax=intercont*ceil(max(max(B))/intercont);
|
---|
[89] | 764 | cont_pos_plus=0:intercont:contmax;
|
---|
| 765 | cont_pos_min=double(contmin):intercont:-intercont;
|
---|
[8] | 766 | cont_pos=[cont_pos_min cont_pos_plus];
|
---|
| 767 | sizpx=(AX(end)-AX(1))/(np(2)-1);
|
---|
| 768 | sizpy=(AY(1)-AY(end))/(np(1)-1);
|
---|
| 769 | x_cont=[AX(1):sizpx:AX(end)]; % pixel x coordinates for image display
|
---|
[89] | 770 | y_cont=AY(1):-sizpy:AY(end); % pixel x coordinates for image display
|
---|
[8] | 771 | txt=ver;%version of Matlab
|
---|
| 772 | Release=txt(1).Release;
|
---|
| 773 | relnumb=str2num(Release(3:4));
|
---|
| 774 | if relnumb >= 14
|
---|
| 775 | vec=linspace(0,1,(abscontmax-abscontmin)/intercont);%define a greyscale colormap with steps intercont
|
---|
| 776 | map=[vec' vec' vec'];
|
---|
| 777 | colormap(map);
|
---|
| 778 | [var,hcontour]=contour(x_cont,y_cont,B,cont_pos);
|
---|
| 779 | set(hcontour,'Fill','on')
|
---|
| 780 | set(hcontour,'LineStyle','none')
|
---|
| 781 | hold on
|
---|
| 782 | end
|
---|
| 783 | [var_p,hcontour_p]=contour(x_cont,y_cont,B,cont_pos_plus,'k-');
|
---|
| 784 | hold on
|
---|
| 785 | [var_m,hcontour_m]=contour(x_cont,y_cont,B,cont_pos_min,':');
|
---|
| 786 | set(hcontour_m,'LineColor',[1 1 1])
|
---|
| 787 | hold off
|
---|
| 788 | caxis([abscontmin abscontmax])
|
---|
| 789 | colormap(map);
|
---|
| 790 | end
|
---|
[89] | 791 | if ~isequal(PlotParam.Scalar.Contours,1)
|
---|
[8] | 792 | % rescale the grey levels with min and max, put a grey scale colorbar
|
---|
[89] | 793 | if BW
|
---|
[8] | 794 | B=A;
|
---|
| 795 | vec=linspace(0,1,255);%define a linear greyscale colormap
|
---|
| 796 | map=[vec' vec' vec'];
|
---|
| 797 | colormap(map); %grey scale color map
|
---|
| 798 | else
|
---|
| 799 | B=A;
|
---|
| 800 | colormap('default'); % standard faulse colors for div, vort , scalar fields
|
---|
| 801 | end
|
---|
| 802 | end
|
---|
[88] | 803 | else %color images
|
---|
[8] | 804 | axes(haxes)
|
---|
[89] | 805 | if BW
|
---|
| 806 | B=uint16(sum(A,3));
|
---|
| 807 | else
|
---|
| 808 | B=uint8(A);
|
---|
| 809 | end
|
---|
[8] | 810 | MinA=0;
|
---|
| 811 | MaxA=255;
|
---|
| 812 | end
|
---|
| 813 | if ~isequal(PlotParam.Scalar.Contours,1)
|
---|
| 814 | %interpolate to increase resolution
|
---|
| 815 | test_interp=1;
|
---|
| 816 | if max(np) <= 64
|
---|
| 817 | npxy=8*np;% increase the resolution 8 times
|
---|
| 818 | elseif max(np) <= 128
|
---|
| 819 | npxy=4*np;% increase the resolution 4 times
|
---|
| 820 | elseif max(np) <= 256
|
---|
| 821 | npxy=2*np;% increase the resolution 2 times
|
---|
| 822 | else
|
---|
| 823 | npxy=np;
|
---|
| 824 | test_interp=0; % no interpolation done
|
---|
| 825 | end
|
---|
[55] | 826 | if test_interp==1%if we interpolate
|
---|
[8] | 827 | x=linspace(AX(1),AX(2),np(2));
|
---|
| 828 | y=linspace(AY(1),AY(2),np(1));
|
---|
| 829 | [X,Y]=meshgrid(x,y);
|
---|
| 830 | xi=linspace(AX(1),AX(2),npxy(2));
|
---|
| 831 | yi=linspace(AY(1),AY(2),npxy(1));
|
---|
| 832 | B = interp2(X,Y,double(B),xi,yi');
|
---|
| 833 | end
|
---|
| 834 | if isempty(hima)
|
---|
| 835 | tag=get(haxes,'Tag');
|
---|
| 836 | hima=imagesc(AX,AY,B,[MinA MaxA]);
|
---|
| 837 | set(hima,'Tag','ima','HitTest','off')
|
---|
| 838 | set(haxes,'Tag',tag);%preserve the axes tag (removed by image fct !!!)
|
---|
| 839 | else
|
---|
| 840 | set(hima,'CData',B);
|
---|
| 841 | if MinA<MaxA
|
---|
| 842 | caxis([MinA MaxA])
|
---|
| 843 | else
|
---|
| 844 | caxis([MinA MinA+1])
|
---|
| 845 | end
|
---|
| 846 | set(hima,'XData',AX);
|
---|
| 847 | set(hima,'YData',AY);
|
---|
| 848 | end
|
---|
| 849 | end
|
---|
| 850 | if ~isstruct(AxeData)
|
---|
| 851 | AxeData=[];
|
---|
| 852 | end
|
---|
| 853 | AxeData.A=A;
|
---|
| 854 | AxeData.AX=[AX(1) AX(end)];
|
---|
| 855 | AxeData.AY=[AY(1) AY(end)];
|
---|
| 856 | test_ima=1;
|
---|
| 857 | %display the colorbar code for B/W images if Poscolorbar not empty
|
---|
[89] | 858 | if siz==2 && exist('PosColorbar','var')&& ~isempty(PosColorbar)
|
---|
[8] | 859 | if isempty(hcol)|~ishandle(hcol)
|
---|
| 860 | hcol=colorbar;%create new colorbar
|
---|
| 861 | end
|
---|
| 862 | if length(PosColorbar)==4
|
---|
| 863 | set(hcol,'Position',PosColorbar)
|
---|
| 864 | end
|
---|
| 865 | YTick=0;%default
|
---|
| 866 | if MaxA>MinA
|
---|
| 867 | if isequal(PlotParam.Scalar.Contours,1)
|
---|
| 868 | colbarlim=get(hcol,'YLim');
|
---|
| 869 | scale_bar=(colbarlim(2)-colbarlim(1))/(abscontmax-abscontmin);
|
---|
| 870 | YTick=cont_pos(2:end-1);
|
---|
| 871 | YTick_scaled=colbarlim(1)+scale_bar*(YTick-abscontmin);
|
---|
| 872 | set(hcol,'YTick',YTick_scaled);
|
---|
| 873 | elseif (isfield(PlotParam.Scalar,'BW') & isequal(PlotParam.Scalar.BW,1))|isa(A,'uint8')| isa(A,'uint16')%images
|
---|
| 874 | hi=get(hcol,'children');
|
---|
| 875 | if iscell(hi)%multiple images in colorbar
|
---|
| 876 | hi=hi{1};
|
---|
| 877 | end
|
---|
| 878 | set(hi,'YData',[MinA MaxA])
|
---|
| 879 | set(hi,'CData',[1:256]')
|
---|
| 880 | set(hcol,'YLim',[MinA MaxA])
|
---|
| 881 | YTick=colbartick(MinA,MaxA);
|
---|
| 882 | set(hcol,'YTick',YTick)
|
---|
| 883 | else
|
---|
| 884 | hi=get(hcol,'children');
|
---|
| 885 | if iscell(hi)%multiple images in colorbar
|
---|
| 886 | hi=hi{1};
|
---|
| 887 | end
|
---|
| 888 | set(hi,'YData',[MinA MaxA])
|
---|
| 889 | set(hi,'CData',[1:64]')
|
---|
| 890 | YTick=colbartick(MinA,MaxA);
|
---|
| 891 | set(hcol,'YLim',[MinA MaxA])
|
---|
| 892 | set(hcol,'YTick',YTick)
|
---|
| 893 | end
|
---|
| 894 | set(hcol,'Yticklabel',num2str(YTick'));
|
---|
| 895 | end
|
---|
| 896 | elseif ishandle(hcol)
|
---|
| 897 | delete(hcol); %erase existing colorbar if not needed
|
---|
| 898 | end
|
---|
| 899 | else%no scalar plot
|
---|
| 900 | if ~isempty(hima) && ishandle(hima)
|
---|
| 901 | delete(hima)
|
---|
| 902 | end
|
---|
| 903 | if ~isempty(hcol)&& ishandle(hcol)
|
---|
| 904 | delete(hcol)
|
---|
| 905 | end
|
---|
| 906 | AxeData.A=[];
|
---|
| 907 | AxeData.AX=[];
|
---|
| 908 | AxeData.AY=[];
|
---|
| 909 | PlotParamOut=rmfield(PlotParamOut,'Scalar');
|
---|
| 910 | end
|
---|
| 911 |
|
---|
| 912 | %%%%%%%%%%%%%%%%%%%%% vector plot %%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
| 913 | if test_vec
|
---|
| 914 | %vector scale representation
|
---|
| 915 | if size(vec_U,1)==numel(vec_Y) && size(vec_U,2)==numel(vec_X); % x, y coordinate variables
|
---|
| 916 | [vec_X,vec_Y]=meshgrid(vec_X,vec_Y);
|
---|
| 917 | end
|
---|
| 918 | vec_X=reshape(vec_X,1,numel(vec_X));%reshape in matlab vectors
|
---|
| 919 | vec_Y=reshape(vec_Y,1,numel(vec_Y));
|
---|
| 920 | vec_U=reshape(vec_U,1,numel(vec_U));
|
---|
| 921 | vec_V=reshape(vec_V,1,numel(vec_V));
|
---|
[73] | 922 | MinMaxX=max(vec_X)-min(vec_X);
|
---|
| 923 | MinMaxY=max(vec_Y)-min(vec_Y);
|
---|
[8] | 924 | AxeData.Mesh=sqrt((MinMaxX*MinMaxY)/length(vec_X));
|
---|
| 925 | if ~isfield(PlotParam.Vectors,'AutoVec') || isequal(PlotParam.Vectors.AutoVec,0)|| ~isfield(PlotParam.Vectors,'VecScale')...
|
---|
| 926 | ||isempty(PlotParam.Vectors.VecScale)||~isa(PlotParam.Vectors.VecScale,'double') %automatic vector scale
|
---|
| 927 | scale=[];
|
---|
| 928 | if test_false %remove false vectors
|
---|
| 929 | indsel=find(AxeData.FF==0);%indsel =indices of good vectors
|
---|
| 930 | else
|
---|
| 931 | indsel=[1:numel(vec_X)];%
|
---|
| 932 | end
|
---|
| 933 | if isempty(vec_U)
|
---|
| 934 | scale=1;
|
---|
| 935 | else
|
---|
| 936 | if isempty(indsel)
|
---|
| 937 | MaxU=max(abs(vec_U));
|
---|
| 938 | MaxV=max(abs(vec_V));
|
---|
| 939 | else
|
---|
| 940 | MaxU=max(abs(vec_U(indsel)));
|
---|
| 941 | MaxV=max(abs(vec_V(indsel)));
|
---|
| 942 | end
|
---|
| 943 | scale=MinMaxX/(max(MaxU,MaxV)*50);
|
---|
| 944 | PlotParam.Vectors.VecScale=scale;%update the 'scale' display
|
---|
| 945 | end
|
---|
| 946 | else
|
---|
| 947 | scale=PlotParam.Vectors.VecScale; %impose the length of vector representation
|
---|
| 948 | end;
|
---|
| 949 |
|
---|
| 950 | %record vectors on the plotting axes
|
---|
| 951 | if test_C==0
|
---|
| 952 | vec_C=ones(1,numel(vec_X));
|
---|
| 953 | end
|
---|
| 954 | AxeData.X=vec_X';
|
---|
| 955 | AxeData.Y=vec_Y';
|
---|
| 956 | AxeData.U=vec_U';
|
---|
| 957 | AxeData.V=vec_V';
|
---|
| 958 | AxeData.C=vec_C';
|
---|
| 959 | if isempty(ivar_F)
|
---|
| 960 | AxeData.F=[];
|
---|
| 961 | else
|
---|
| 962 | AxeData.F=vec_F';
|
---|
| 963 | end
|
---|
| 964 | if isempty(ivar_FF)
|
---|
| 965 | AxeData.FF=[];
|
---|
| 966 | else
|
---|
| 967 | AxeData.FF=vec_FF';
|
---|
| 968 | end
|
---|
| 969 | % if isfield(Data,'W')
|
---|
| 970 | % AxeData.W=Data.W;
|
---|
| 971 | % end
|
---|
| 972 |
|
---|
| 973 | %decimate by a factor 2 in vector mesh(4 in nbre of vectors)
|
---|
| 974 | if isfield(PlotParam.Vectors,'decimate4')&isequal(PlotParam.Vectors.decimate4,1)
|
---|
| 975 | diffy=diff(vec_Y); %difference dy=vec_Y(i+1)-vec_Y(i)
|
---|
| 976 | dy_thresh=max(abs(diffy))/2;
|
---|
| 977 | ind_jump=find(abs(diffy) > dy_thresh); %indices with diff(vec_Y)> max/2, detect change of line
|
---|
[89] | 978 | ind_sel=1:ind_jump(1);%select the first line
|
---|
[8] | 979 | for i=2:2:length(ind_jump)-1
|
---|
| 980 | ind_sel=[ind_sel [ind_jump(i)+1:ind_jump(i+1)]];% select the odd lines
|
---|
| 981 | end
|
---|
| 982 | nb_sel=length(ind_sel);
|
---|
| 983 | ind_sel=ind_sel([1:2:nb_sel]);% take half the points on a line
|
---|
| 984 | vec_X=vec_X(ind_sel);
|
---|
| 985 | vec_Y=vec_Y(ind_sel);
|
---|
| 986 | vec_U=vec_U(ind_sel);
|
---|
| 987 | vec_V=vec_V(ind_sel);
|
---|
| 988 | vec_C=vec_C(ind_sel);
|
---|
| 989 | if ~isempty(ivar_F)
|
---|
| 990 | vec_F=vec_F(ind_sel);
|
---|
| 991 | end
|
---|
| 992 | if ~isempty(ivar_FF)
|
---|
| 993 | vec_FF=vec_FF(ind_sel);
|
---|
| 994 | end
|
---|
| 995 | end
|
---|
| 996 |
|
---|
| 997 | %get main level color code
|
---|
| 998 | [colorlist,col_vec,PlotParamOut.Vectors]=set_col_vec(PlotParam.Vectors,vec_C);
|
---|
| 999 | % take flags into account: add flag colors to the list of colors
|
---|
| 1000 | sizlist=size(colorlist);
|
---|
| 1001 | nbcolor=sizlist(1);
|
---|
| 1002 | if test_black
|
---|
| 1003 | nbcolor=nbcolor+1;
|
---|
| 1004 | colorlist(nbcolor,:)=[0 0 0]; %add black to the list of colors
|
---|
| 1005 | if ~isempty(ivar_FF)
|
---|
[74] | 1006 | ind_flag=find(vec_F~=1 & vec_F~=0 & vec_FF==0); %flag warning but not false
|
---|
[8] | 1007 | else
|
---|
[74] | 1008 | ind_flag=find(vec_F~=1 & vec_F~=0);
|
---|
[8] | 1009 | end
|
---|
| 1010 | col_vec(ind_flag)=nbcolor;
|
---|
| 1011 | end
|
---|
| 1012 | nbcolor=nbcolor+1;
|
---|
| 1013 | if ~isempty(ivar_FF)
|
---|
| 1014 | ind_flag=find(vec_FF~=0);
|
---|
| 1015 | if isfield(PlotParam.Vectors,'HideFalse') && PlotParam.Vectors.HideFalse==1
|
---|
| 1016 | colorlist(nbcolor,:)=[NaN NaN NaN];% no plot of false vectors
|
---|
| 1017 | else
|
---|
| 1018 | colorlist(nbcolor,:)=[1 0 1];% magenta color
|
---|
| 1019 | end
|
---|
| 1020 | col_vec(ind_flag)=nbcolor;
|
---|
| 1021 | end
|
---|
| 1022 | %plot vectors:
|
---|
| 1023 | quiresetn(haxes,vec_X,vec_Y,vec_U,vec_V,scale,colorlist,col_vec);
|
---|
| 1024 | else
|
---|
| 1025 | hvec=findobj(haxes,'Tag','vel');
|
---|
| 1026 | if ~isempty(hvec)
|
---|
| 1027 | delete(hvec);
|
---|
| 1028 | end
|
---|
| 1029 | AxeData.X=[];
|
---|
| 1030 | AxeData.Y=[];
|
---|
| 1031 | AxeData.U=[];
|
---|
| 1032 | AxeData.V=[];
|
---|
| 1033 | AxeData.C=[];
|
---|
| 1034 | AxeData.W=[];
|
---|
| 1035 | AxeData.F=[];
|
---|
| 1036 | AxeData.FF=[];
|
---|
| 1037 | AxeData.Mesh=[];
|
---|
| 1038 | PlotParamOut=rmfield(PlotParamOut,'Vectors');
|
---|
| 1039 | end
|
---|
| 1040 | if isfield(Data,'Z')
|
---|
| 1041 | AxeData.Z=Data.Z;% A REVOIR
|
---|
| 1042 | end
|
---|
| 1043 | listfields={'AY','AX','A','X','Y','U','V','C','W','F','FF'};
|
---|
| 1044 | listdim={'AY','AX',{'AY','AX'},'nb_vectors','nb_vectors','nb_vectors','nb_vectors','nb_vectors','nb_vectors','nb_vectors','nb_vectors'};
|
---|
| 1045 | Role={'coord_y','coord_x','scalar','coord_x','coord_y','vector_x','vector_y','scalar','vector_z','warnflag','errorflag'};
|
---|
| 1046 | ind_select=[];
|
---|
| 1047 | nbvar=0;
|
---|
| 1048 | AxeData.ListVarName={};
|
---|
| 1049 | AxeData.VarDimName={};
|
---|
| 1050 | AxeData.VarAttribute={};
|
---|
| 1051 | for ilist=1:numel(listfields)
|
---|
| 1052 | eval(['testvar=isfield(AxeData,listfields{ilist}) && ~isempty(AxeData.' listfields{ilist} ');'])
|
---|
| 1053 | if testvar
|
---|
| 1054 | nbvar=nbvar+1;
|
---|
| 1055 | AxeData.ListVarName{nbvar}=listfields{ilist};
|
---|
| 1056 | AxeData.VarDimName{nbvar}=listdim{ilist};
|
---|
| 1057 | AxeData.VarAttribute{nbvar}.Role=Role{ilist};
|
---|
| 1058 | end
|
---|
| 1059 | end
|
---|
[82] | 1060 | %store the coordinate extrema occupied by the field
|
---|
| 1061 | test_lim=0;
|
---|
| 1062 | if test_vec
|
---|
| 1063 | Xlim=[min(vec_X) max(vec_X)];
|
---|
| 1064 | Ylim=[min(vec_Y) max(vec_Y)];
|
---|
| 1065 | test_lim=1;
|
---|
| 1066 | if test_ima%both background image and vectors coexist, take the wider bound
|
---|
| 1067 | Xlim(1)=min(AX(1),Xlim(1));
|
---|
| 1068 | Xlim(2)=max(AX(end),Xlim(2));
|
---|
| 1069 | Ylim(1)=min(AY(end),Ylim(1));
|
---|
| 1070 | Ylim(2)=max(AY(1),Ylim(2));
|
---|
| 1071 | end
|
---|
| 1072 | elseif test_ima %only image plot
|
---|
| 1073 | Xlim(1)=min(AX(1),AX(end));
|
---|
| 1074 | Xlim(2)=max(AX(1),AX(end));
|
---|
| 1075 | Ylim(1)=min(AY(1),AY(end));
|
---|
| 1076 | Ylim(2)=max(AY(1),AY(end));
|
---|
| 1077 | test_lim=1;
|
---|
| 1078 | end
|
---|
| 1079 | AxeData.RangeX=Xlim;
|
---|
| 1080 | AxeData.RangeY=Ylim;
|
---|
[72] | 1081 | % adjust the size of the plot to include the whole field, except if PlotParam.FixedLimits=1
|
---|
[82] | 1082 | if ~(isfield(PlotParam,'FixedLimits') && PlotParam.FixedLimits) && test_lim
|
---|
| 1083 | if Xlim(2)>Xlim(1)
|
---|
| 1084 | set(haxes,'XLim',Xlim);% set x limits of frame in axes coordinates
|
---|
[8] | 1085 | end
|
---|
[82] | 1086 | if Ylim(2)>Ylim(1)
|
---|
| 1087 | set(haxes,'YLim',Ylim);% set y limits of frame in axes coordinate
|
---|
| 1088 | end
|
---|
[8] | 1089 | end
|
---|
| 1090 | if ~(isfield(PlotParam,'Auto_xy') && isequal(PlotParam.Auto_xy,1))
|
---|
| 1091 | set(haxes,'DataAspectRatio',[1 1 1])
|
---|
| 1092 | end
|
---|
| 1093 | set(haxes,'YDir','normal')
|
---|
| 1094 | set(get(haxes,'XLabel'),'String',[XName x_units]);
|
---|
| 1095 | set(get(haxes,'YLabel'),'String',[YName y_units]);
|
---|
[72] | 1096 |
|
---|
| 1097 | %-------------------------------------------------------------------
|
---|
| 1098 | % --- function for plotting vectors
|
---|
[8] | 1099 | %INPUT:
|
---|
| 1100 | % haxes: handles of the plotting axes
|
---|
| 1101 | %x,y,u,v: vectors coordinates and vector components to plot, arrays withb the same dimension
|
---|
| 1102 | % scale: scaling factor for vector length representation
|
---|
| 1103 | %colorlist(icolor,:): list of vector colors, dim (nbcolor,3), depending on color #i
|
---|
| 1104 | %col_vec: matlab vector setting the color number #i for each velocity vector
|
---|
| 1105 | function quiresetn(haxes,x,y,u,v,scale,colorlist,col_vec)
|
---|
[72] | 1106 | %-------------------------------------------------------------------
|
---|
[8] | 1107 | %define arrows
|
---|
| 1108 | theta=0.5 ;%angle arrow
|
---|
| 1109 | alpha=0.3 ;%length arrow
|
---|
| 1110 | rot=alpha*[cos(theta) -sin(theta); sin(theta) cos(theta)]';
|
---|
| 1111 | %find the existing lines
|
---|
| 1112 | %h=findobj(gca,'Type','Line');% search existing lines in the current axes
|
---|
| 1113 | h=findobj(haxes,'Tag','vel');% search existing lines in the current axes
|
---|
| 1114 | sizh=size(h);
|
---|
| 1115 | set(h,'EraseMode','xor');
|
---|
| 1116 | set(haxes,'NextPlot','replacechildren');
|
---|
| 1117 | %htext=findobj('Tag','scalevec');
|
---|
| 1118 |
|
---|
| 1119 | %drawnow
|
---|
| 1120 | %create lines (if no lines) or modify them
|
---|
| 1121 | if ~isequal(size(col_vec),size(x))
|
---|
| 1122 | col_vec=ones(size(x));% case of error in col_vec input
|
---|
| 1123 | end
|
---|
| 1124 | sizlist=size(colorlist);
|
---|
| 1125 | ncolor=sizlist(1);
|
---|
| 1126 |
|
---|
| 1127 | for icolor=1:ncolor
|
---|
| 1128 | %determine the line positions for each color icolor
|
---|
| 1129 | ind=find(col_vec==icolor);
|
---|
| 1130 | xc=x(ind);
|
---|
| 1131 | yc=y(ind);
|
---|
| 1132 | uc=u(ind)*scale;
|
---|
| 1133 | vc=v(ind)*scale;
|
---|
| 1134 | n=size(xc);
|
---|
| 1135 | xN=NaN*ones(size(xc));
|
---|
| 1136 | matx=[xc(:) xc(:)+uc(:) xN(:)]';
|
---|
| 1137 | matx=reshape(matx,1,3*n(2));
|
---|
| 1138 | maty=[yc(:) yc(:)+vc(:) xN(:)]';
|
---|
| 1139 | maty=reshape(maty,1,3*n(2));
|
---|
| 1140 |
|
---|
| 1141 | %determine arrow heads
|
---|
| 1142 | arrowplus=rot*[uc;vc];
|
---|
| 1143 | arrowmoins=rot'*[uc;vc];
|
---|
| 1144 | x1=xc+uc-arrowplus(1,:);
|
---|
| 1145 | x2=xc+uc;
|
---|
| 1146 | x3=xc+uc-arrowmoins(1,:);
|
---|
| 1147 | y1=yc+vc-arrowplus(2,:);
|
---|
| 1148 | y2=yc+vc;
|
---|
| 1149 | y3=yc+vc-arrowmoins(2,:);
|
---|
| 1150 | matxar=[x1(:) x2(:) x3(:) xN(:)]';
|
---|
| 1151 | matxar=reshape(matxar,1,4*n(2));
|
---|
| 1152 | matyar=[y1(:) y2(:) y3(:) xN(:)]';
|
---|
| 1153 | matyar=reshape(matyar,1,4*n(2));
|
---|
| 1154 | %draw the line or modify the existing ones
|
---|
| 1155 | isn=isnan(colorlist(icolor,:));%test if color NaN
|
---|
| 1156 | if 2*icolor > sizh(1) %if icolor exceeds the number of existing ones
|
---|
| 1157 | axes(haxes)
|
---|
| 1158 | if ~isn(1) %if the vectors are visible color not nan
|
---|
| 1159 | if n(2)>0
|
---|
| 1160 | hold on
|
---|
| 1161 | line(matx,maty,'Color',colorlist(icolor,:),'Tag','vel');% plot new lines
|
---|
| 1162 | line(matxar,matyar,'Color',colorlist(icolor,:),'Tag','vel');% plot arrows
|
---|
| 1163 | end
|
---|
| 1164 | end
|
---|
| 1165 | else
|
---|
| 1166 | if isn(1)
|
---|
| 1167 | delete(h(2*icolor-1))
|
---|
| 1168 | delete(h(2*icolor))
|
---|
| 1169 | else
|
---|
| 1170 | set(h(2*icolor-1),'Xdata',matx,'Ydata',maty);
|
---|
| 1171 | set(h(2*icolor-1),'Color',colorlist(icolor,:));
|
---|
| 1172 | set(h(2*icolor-1),'EraseMode','xor');
|
---|
| 1173 | set(h(2*icolor),'Xdata',matxar,'Ydata',matyar);
|
---|
| 1174 | set(h(2*icolor),'Color',colorlist(icolor,:));
|
---|
| 1175 | set(h(2*icolor),'EraseMode','xor');
|
---|
| 1176 | end
|
---|
| 1177 | end
|
---|
| 1178 | end
|
---|
| 1179 | if sizh(1) > 2*ncolor
|
---|
| 1180 | for icolor=ncolor+1 : sizh(1)/2%delete additional objects
|
---|
| 1181 | delete(h(2*icolor-1))
|
---|
| 1182 | delete(h(2*icolor))
|
---|
| 1183 | end
|
---|
| 1184 | end
|
---|
| 1185 |
|
---|
[72] | 1186 | %-------------------------------------------------------------------
|
---|
| 1187 | % ---- determine tick positions for colorbar
|
---|
[8] | 1188 | function YTick=colbartick(MinA,MaxA)
|
---|
[72] | 1189 | %-------------------------------------------------------------------
|
---|
[8] | 1190 | %determine tick positions with "simple" values between MinA and MaxA
|
---|
| 1191 | YTick=0;%default
|
---|
| 1192 | maxabs=max([abs(MinA) abs(MaxA)]);
|
---|
| 1193 | if maxabs>0
|
---|
| 1194 | ord=10^(floor(log10(maxabs)));%order of magnitude
|
---|
| 1195 | div=1;
|
---|
| 1196 | siz2=1;
|
---|
| 1197 | while siz2<2
|
---|
| 1198 | % values=[-9:div:9];
|
---|
| 1199 | values=-10:div:10;
|
---|
| 1200 | ind=find((ord*values-MaxA)<0 & (ord*values-MinA)>0);%indices of 'values' such that MinA<ord*values<MaxA
|
---|
| 1201 | siz=size(ind);
|
---|
| 1202 | if siz(2)<4%if there are less than 4 selected values (4 levels)
|
---|
[89] | 1203 | values=-9:0.5*div:9;
|
---|
[8] | 1204 | ind=find((ord*values-MaxA)<0 & (ord*values-MinA)>0);
|
---|
| 1205 | end
|
---|
| 1206 | siz2=size(ind,2);
|
---|
| 1207 | % siz2=siz(2)
|
---|
| 1208 | div=div/10;
|
---|
| 1209 | end
|
---|
| 1210 | YTick=ord*values(ind);
|
---|
| 1211 | end |
---|