Changeset 187 for trunk/src/plot_field.m


Ignore:
Timestamp:
Feb 1, 2011, 1:07:28 AM (13 years ago)
Author:
sommeria
Message:

various bug repairs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plot_field.m

    r186 r187  
    101101%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    102102
    103 function [PlotType,PlotParamOut,haxes]= plot_field(Data,haxes,PlotParam,htext,PosColorbar)
     103function [PlotType,PlotParamOut,haxes]= plot_field(Data,haxes,PlotParam,PosColorbar)
    104104% TODO:
    105105% use htext: handles of the text edit box (uicontrol)
    106106% introduce PlotParam.Hold: 'on' or 'off' (for curves)
    107 
    108107%default output
    109108if ~exist('PlotParam','var'),PlotParam=[];end;
    110 if ~exist('htext','var'),htext=[];end;
    111109if ~exist('PosColorbar','var'),PosColorbar=[];end;
    112110PlotType='text'; %default
    113111PlotParamOut=PlotParam;%default
    114 if isempty(Data)
    115     PlotType='none';
    116    return
    117 end
    118 % check input structure
    119 [Data,errormsg]=check_field_structure(Data);
    120 
    121 if ~isempty(errormsg)
    122     msgbox_uvmat('ERROR',['input of plot_field/check_field_structure: ' errormsg])
    123     display(['input of plot_field/check_field_structure:: ' errormsg])
    124     return
    125 end
    126 
     112
     113%% test axes and figure
    127114testnewfig=1;%test to create a new figure (default)
    128115testzoomaxes=0;%test for the existence of a zoom secondary figure attached to the plotting axes
     
    130117    if ishandle(haxes)
    131118        if isequal(get(haxes,'Type'),'axes')
    132 %             axes(haxes)
    133119            testnewfig=0;
    134120            AxeData=get(haxes,'UserData');
     
    145131    PlotParam=read_plot_param(PlotParam);   
    146132end
    147 if testnewfig% create a new figure and axes if the plotting axes does not exist
     133% create a new figure and axes if the plotting axes does not exist
     134if testnewfig
    148135    hfig=figure;
    149136    if isfield(PlotParam,'text_display_1') && ishandle(PlotParam.text_display_1)
     
    163150end
    164151
    165 if isfield(PlotParam,'Auto_xy') && isequal(PlotParam.Auto_xy,1)
    166     set(haxes,'DataAspectRatioMode','auto')%automatic aspect ratio
    167 end
    168 
    169 %% check the cells of fields :
    170 [CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Data);
     152%% check input structure
     153if ~isempty(Data)
     154    [Data,errormsg]=check_field_structure(Data);
     155
     156    if ~isempty(errormsg)
     157        msgbox_uvmat('ERROR',['input of plot_field/check_field_structure: ' errormsg])
     158        display(['input of plot_field/check_field_structure:: ' errormsg])
     159        return
     160    end
     161
     162    %% check the cells of fields :
     163    [CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Data);
     164
     165    if ~isempty(errormsg)
     166        msgbox_uvmat('ERROR',['input of plot_field/find_field_indices: ' errormsg]);
     167        return
     168    end
     169    index_3D=find(NbDim>2,1);
     170    if ~isempty(index_3D)
     171        msgbox_uvmat('ERROR','volume plot not implemented yet');
     172        return
     173    end
     174    index_2D=find(NbDim==2,2);%find 2D fields (at most 2)
     175    index_1D=find(NbDim==1);
     176    index_0D=find(NbDim==0);
     177   
     178        %% set axes properties
     179    if isfield(PlotParam,'FixedLimits') && isequal(PlotParam.FixedLimits,1)  %adjust the graph limits*
     180        set(haxes,'XLimMode', 'manual')
     181        set(haxes,'YLimMode', 'manual')
     182    else
     183        set(haxes,'XLimMode', 'auto')
     184        set(haxes,'YLimMode', 'auto')
     185    end
     186    if isfield(PlotParam,'Auto_xy') && isequal(PlotParam.Auto_xy,1)
     187        set(haxes,'DataAspectRatioMode','auto')%automatic aspect ratio
     188    else
     189        set(haxes,'DataAspectRatioMode','manual')
     190    end
     191else
     192    index_2D=[];
     193    index_1D=[];
     194    index_0D=[];
     195end
    171196
    172197%% plot if the input field is valid
     198PlotType='text';
     199errormsg=[];
     200AxeData=get(haxes,'UserData');
     201if isempty(index_2D)
     202    plot_plane([],[],[],haxes);%removes images or vector plots if any
     203else
     204         [xx,PlotParamOut,PlotType,errormsg]=plot_plane(Data,CellVarIndex(index_2D),VarType(index_2D),haxes,PlotParam,PosColorbar);
     205         AxeData.NbDim=2;
     206            if testzoomaxes && isempty(errormsg)
     207                [zoomaxes,PlotParamOut,xx,errormsg]=plot_plane(Data,CellVarIndex(index_2D),VarType(index_2D),zoomaxes,PlotParam,PosColorbar);
     208                AxeData.ZoomAxes=zoomaxes;
     209            end
     210end
     211if isempty(index_1D)
     212     plot_profile([],[],[],haxes);%
     213else
     214        plot_profile(Data,CellVarIndex(index_1D),VarType(index_1D),haxes,PlotParam);%
     215        if testzoomaxes
     216            [zoomaxes,PlotParamOut]=plot_profile(Data,CellVarIndex(index_1D),VarType(index_1D),zoomaxes,PlotParam);
     217            AxeData.ZoomAxes=zoomaxes;
     218        end
     219        PlotType='line';
     220end
     221htext=findobj(hfig,'Tag','text_display');
     222if ~isempty(htext)
     223    if isempty(index_0D)
     224        set(htext,'String',{''})
     225    else
     226        [errormsg]=plot_text(Data,CellVarIndex(index_0D),htext);
     227    end
     228end
     229
    173230if ~isempty(errormsg)
    174     errormsg=['input of plot_field/find_field_indices: ' errormsg];
    175 else
    176     if ~isfield(Data,'NbDim') %& ~isfield(Data,'Style')%determine the space dimensionb if not defined: choose the kind of plot
    177         [Data.NbDim]=max(NbDim);
    178     end
    179     if isequal(Data.NbDim,0)
    180             AxeData=plot_text(Data,htext);
    181             PlotType='text';
    182             errormsg=[];
    183     elseif isequal(Data.NbDim,1)
    184         [AxeData]=plot_profile(Data,CellVarIndex,VarType,haxes,PlotParam);%
    185         if testzoomaxes
    186             [AxeData,zoomaxes,PlotParamOut]=plot_profile(Data,CellVarIndex,VarType,zoomaxes,PlotParam);
    187             AxeData.ZoomAxes=zoomaxes;
    188         end
    189         PlotType='line';
    190         errormsg=[];
    191     elseif isequal(Data.NbDim,2)
    192         ind_select=find(NbDim>=2);
    193         if numel(ind_select)>2
    194             errormsg='more than two fields to map';
    195         else
    196             [AxeData,xx,PlotParamOut,PlotType,errormsg]=plot_plane(Data,CellVarIndex(ind_select),VarType(ind_select),haxes,PlotParam,htext,PosColorbar);
    197             if testzoomaxes && isempty(errormsg)
    198                 [AxeData,zoomaxes,PlotParamOut,xx,errormsg]=plot_plane(Data,CellVarIndex(ind_select),VarType(ind_select),zoomaxes,PlotParam,1,PosColorbar);
    199                 Data.ZoomAxes=zoomaxes;
    200             end
    201         end
    202     elseif isequal(Data.NbDim,3)
    203         errormsg='volume plot not implemented yet';
    204     end
    205 end
    206 if isempty(errormsg)
    207     set(haxes,'UserData',Data)
    208 else
    209231    msgbox_uvmat('ERROR', errormsg)
    210232end
    211233
    212 
     234%% update the parameters stored in AxeData
     235set(haxes,'UserData',AxeData)
     236
     237%% update the parameters stored in parent figure
     238FigData=get(hfig,'UserData');
     239tagaxes=get(haxes,'tag');
     240if isfield(FigData,tagaxes)
     241    eval(['FigData.' tagaxes '=Data'])
     242    set(hfig,'UserData',FigData)
     243end
     244             
    213245%-------------------------------------------------------------------
    214 function hdisplay=plot_text(FieldData,hdisplay_in)
     246function errormsg=plot_text(FieldData,CellVarIndex,htext)
    215247%-------------------------------------------------------------------
    216 if exist('hdisplay_in','var') && ~isempty(hdisplay_in) && ishandle(hdisplay_in) && isequal(get(hdisplay_in,'Type'),'uicontrol')
    217     hdisplay=hdisplay_in;
    218 else
    219     figure;%create new figure
    220     hdisplay=uicontrol('Style','edit', 'Units','normalized','Position', [0 0 1 1],'Max',2,'FontName','monospaced');
    221 end
    222    
    223 ff=fields(FieldData);%list of field names
    224 vv=struct2cell(FieldData);%list of field values
    225 
    226 for icell=1:length(vv)
    227     Tabcell{icell,1}=ff{icell};
    228     ss=vv{icell};
    229     sizss=size(ss);
    230     if isnumeric(ss)
    231         if sizss(1)<=1 && length(ss)<5
    232             displ{icell}=num2str(ss);
    233         else
    234             displ{icell}=[class(ss) ', size ' num2str(size(ss))];
    235         end
    236     elseif ischar(ss)
    237         displ{icell}=ss;
    238     elseif iscell(ss)
    239         sizcell=size(ss);
    240         if sizcell(1)==1 && length(sizcell)==2 %line cell
    241            ssline='{''';
    242            for icolumn=1:sizcell(2)
    243                if isnumeric(ss{icolumn})
    244                    if size(ss{icolumn},1)<=1 && length(ss{icolumn})<5
    245                       sscolumn=num2str(ss{icolumn});%line vector
    246                    else
    247                       sscolumn=[class(ss{icolumn}) ', size ' num2str(size(ss{icolumn}))];
    248                    end
    249                elseif ischar(ss{icolumn})
    250                    sscolumn=ss{icolumn};
    251                else
    252                    sscolumn=class(ss{icolumn});
    253                end
    254                if icolumn==1
    255                    ssline=[ssline sscolumn];
    256                else
    257                    ssline=[ssline ''',''' sscolumn];
    258                end
    259            end
    260            displ{icell}=[ssline '''}'];
    261         else
    262            displ{icell}=[class(ss) ', size ' num2str(sizcell)];
    263         end
    264     else
    265         displ{icell}=class(ss);
    266     end
    267     Tabcell{icell,2}=displ{icell};
    268 end
    269 Tabchar=cell2tab(Tabcell,': ');
    270 set(hdisplay,'String', Tabchar)
     248% if exist('hdisplay_in','var') && ~isempty(hdisplay_in) && ishandle(hdisplay_in) && isequal(get(hdisplay_in,'Type'),'uicontrol')
     249%     hdisplay=hdisplay_in;
     250% else
     251%     figure;%create new figure
     252%     hdisplay=uicontrol('Style','edit', 'Units','normalized','Position', [0 0 1 1],'Max',2,'FontName','monospaced');
     253% end
     254errormsg=[];
     255txt_cell={};
     256for icell=1:length(CellVarIndex)
     257    VarIndex=CellVarIndex{icell};%  indices of the selected variables in the list data.ListVarName
     258% ff=fields(FieldData);%list of field names
     259% vv=struct2cell(FieldData);%list of field values
     260%
     261% for icell=1:length(vv)
     262    for ivar=1:length(VarIndex)
     263         VarName=FieldData.ListVarName{VarIndex(ivar)};
     264         eval(['VarValue=FieldData.' VarName ';'])
     265         if size(VarValue,1)~=1
     266             VarValue=VarValue';
     267         end
     268         txt=[VarName '=' num2str(VarValue)];
     269         txt_cell=[txt_cell;{txt}];
     270    end
     271end
     272
     273set(htext,'String',txt_cell)
     274%     txt_cell=[txt_cell {num2str(
     275%     Tabcell{icell,1}=ff{icell};
     276%     ss=vv{icell};
     277%     sizss=size(ss);
     278%     if isnumeric(ss)
     279%         if sizss(1)<=1 && length(ss)<5
     280%             displ{icell}=num2str(ss);
     281%         else
     282%             displ{icell}=[class(ss) ', size ' num2str(size(ss))];
     283%         end
     284%     elseif ischar(ss)
     285%         displ{icell}=ss;
     286%     elseif iscell(ss)
     287%         sizcell=size(ss);
     288%         if sizcell(1)==1 && length(sizcell)==2 %line cell
     289%            ssline='{''';
     290%            for icolumn=1:sizcell(2)
     291%                if isnumeric(ss{icolumn})
     292%                    if size(ss{icolumn},1)<=1 && length(ss{icolumn})<5
     293%                       sscolumn=num2str(ss{icolumn});%line vector
     294%                    else
     295%                       sscolumn=[class(ss{icolumn}) ', size ' num2str(size(ss{icolumn}))];
     296%                    end
     297%                elseif ischar(ss{icolumn})
     298%                    sscolumn=ss{icolumn};
     299%                else
     300%                    sscolumn=class(ss{icolumn});
     301%                end
     302%                if icolumn==1
     303%                    ssline=[ssline sscolumn];
     304%                else
     305%                    ssline=[ssline ''',''' sscolumn];
     306%                end
     307%            end
     308%            displ{icell}=[ssline '''}'];
     309%         else
     310%            displ{icell}=[class(ss) ', size ' num2str(sizcell)];
     311%         end
     312%     else
     313%         displ{icell}=class(ss);
     314%     end
     315%     Tabcell{icell,2}=displ{icell};
     316% end
     317% Tabchar=cell2tab(Tabcell,': ');
     318% set(hdisplay,'String', Tabchar)
    271319
    272320
    273321%-------------------------------------------------------------------
    274 function [AxeData,haxes]=plot_profile(data,CellVarIndex,VarType,haxes,PlotParam)
     322function [haxes]=plot_profile(data,CellVarIndex,VarType,haxes,PlotParam)
    275323%-------------------------------------------------------------------
    276 %TODO: modify existing plot if it exists
    277 
    278324hfig=get(haxes,'parent');
    279 AxeData=[];%data;
     325%suppress existing plot isf empty data
     326if isempty(data)
     327    hplot=findobj(haxes,'tag','plot_line');
     328    if ~isempty(hplot)
     329        delete(hplot)
     330    end
     331    hlegend=findobj(hfig,'tag','legend');
     332    if ~isempty(hlegend)
     333        delete(hlegend)
     334    end
     335    return
     336end
     337
    280338
    281339ColorOrder=[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];
     
    285343end
    286344% adjust the size of the plot to include the whole field,
    287 if isfield(PlotParam,'FixedLimits') && isequal(PlotParam.FixedLimits,1)  %adjust the graph limits*
    288     set(haxes,'XLimMode', 'manual')
    289     set(haxes,'YLimMode', 'manual')
    290 else
    291     set(haxes,'XLimMode', 'auto')
    292     set(haxes,'YLimMode', 'auto')
    293 end
     345
    294346legend_str={};
    295347
     
    297349%initiate  the plot command
    298350plotstr='hhh=plot(';
    299 textmean={};
     351% textmean={};
    300352coord_x_index=[];
     353xtitle='';
     354ytitle='';
    301355test_newplot=1;
    302 % hh=findobj(haxes,'tag','plot_line');
    303 % num_curve=numel(hh);
    304 % icurve=0;
    305356
    306357%loop on input  fields
     
    311362    else
    312363        coord_x_index_cell=VarType{icell}.coord(1);
    313         if isequal(coord_x_index_cell,0)
    314             continue  % the cell has no abscissa, skip it
    315         end
    316         if ~isempty(coord_x_index)&&~isequal(coord_x_index_cell,coord_x_index)
    317             continue %all the selected variables must have the same first dimension
    318         else
    319             coord_x_index=coord_x_index_cell;
    320         end
     364         if isequal(coord_x_index_cell,0)
     365             continue  % the cell has no abscissa, skip it
     366         end
     367%         if ~isempty(coord_x_index)&&~isequal(coord_x_index_cell,coord_x_index)
     368%             %continue %all the selected variables must have the same first dimension
     369%         else
     370%             coord_x_index=coord_x_index_cell;
     371%         end
     372          coord_x_index=coord_x_index_cell;
    321373    end
    322374    testplot=ones(size(data.ListVarName));%default test for plotted variables
    323     xtitle=data.ListVarName{coord_x_index};
     375    xtitle=[xtitle data.ListVarName{coord_x_index}];
    324376    eval(['coord_x{icell}=data.' data.ListVarName{coord_x_index} ';']);%coordinate variable set as coord_x
    325377    if isfield(data,'VarAttribute')&& numel(data.VarAttribute)>=coord_x_index && isfield(data.VarAttribute{coord_x_index},'units')
    326         xtitle=[xtitle '(' data.VarAttribute{coord_x_index}.units ')'];
     378        xtitle=[xtitle '(' data.VarAttribute{coord_x_index}.units '), '];
     379    else
     380        xtitle=[xtitle ', '];
    327381    end
    328382    eval(['coord_x{icell}=data.' data.ListVarName{coord_x_index} ';']);%coordinate variable set as coord_x
     
    344398        end
    345399    end
    346     %     test_newplot=0;%default
    347     %     if num_curve>=icurve+numel(find(testplot(VarIndex)))%update existing curves
    348     %         if ~isempty(VarType{icell}.discrete')
    349     %             charplot_0='+';
    350     %             LineStyle='none';
    351     %         else
    352     %             charplot_0='none';
    353     %             LineStyle='-';
    354     %         end
    355     %         for ivar=1:length(VarIndex)
    356     %             if testplot(VarIndex(ivar))
    357     %                 icurve=icurve+1;
    358     %                 VarName=data.ListVarName{VarIndex(ivar)};
    359     %                 eval(['data.' VarName '=squeeze(data.' VarName ');'])
    360     %                 set(hh(icurve),'LineStyle',LineStyle)
    361     %                 set(hh(icurve),'Marker',charplot_0)
    362     %                 set(hh(icurve),'XData',coord_x{icell})
    363     %                 eval(['yy=data.' VarName ';'])
    364     %                 set(hh(icurve),'YData',yy);
    365     %             end
    366     %         end
    367     %     else% new plot
    368400    if ~isempty(VarType{icell}.discrete')
    369401        charplot_0='''+''';
     
    374406        if testplot(VarIndex(ivar))
    375407            VarName=data.ListVarName{VarIndex(ivar)};
     408            ytitle=[ytitle VarName];
     409            if isfield(data,'VarAttribute')&& numel(data.VarAttribute)>=VarIndex(ivar) && isfield(data.VarAttribute{VarIndex(ivar)},'units')
     410                ytitle=[ytitle '(' data.VarAttribute{VarIndex(ivar)}.units '), '];
     411            else
     412                ytitle=[ytitle ', '];
     413            end
    376414            eval(['data.' VarName '=squeeze(data.' VarName ');'])
    377415            plotstr=[plotstr 'coord_x{' num2str(icell) '},data.' VarName ',' charplot_0 ','];
     
    381419                coord_x{icell}=linspace(coord_x{icell}(1),coord_x{icell}(2),nbcomponent1);
    382420            end
    383             eval(['varmean=mean(double(data.' VarName '));']);%mean value
    384             textmean=[textmean; {[VarName 'mean= ' num2str(varmean,4)]}];
     421            %eval(['varmean=mean(double(data.' VarName '));']);%mean value
     422            %textmean=[textmean; {[VarName 'mean= ' num2str(varmean,4)]}];
    385423            if nbcomponent1==1|| nbcomponent2==1
    386424                legend_str=[legend_str {VarName}]; %variable with one component
     
    395433
    396434%% activate the plot
    397 if test_newplot && ~isequal(plotstr,'hhh=plot(')
    398     plotstr=[plotstr '''tag'',''plot_line'');'];
    399                 %execute plot (instruction  plotstr)
    400 %     set(hfig,'CurrentAxes',haxes)
    401 %     axes(haxes)% select the plotting axes for plot operation
    402     eval(plotstr)
    403    
    404                 %%%%%
     435if test_newplot && ~isequal(plotstr,'hhh=plot(') 
     436    set(hfig,'CurrentAxes',haxes)
     437    tag=get(haxes,'tag');
     438   
     439    %%%
     440    plotstr=[plotstr '''tag'',''plot_line'');'];   
     441    eval(plotstr)                  %execute plot (instruction  plotstr)
     442    %%%
     443   
     444    set(haxes,'tag',tag)
    405445    grid(haxes, 'on')
    406     hxlabel=xlabel(xtitle);
     446    hxlabel=xlabel(xtitle(1:end-2));% xlabel (removes ', ' at the end)
    407447    set(hxlabel,'Interpreter','none')% desable tex interpreter
    408448    if length(legend_str)>=1
    409         hylabel=ylabel(legend_str{end});
     449        hylabel=ylabel(ytitle(1:end-2));% ylabel (removes ', ' at the end)
    410450        set(hylabel,'Interpreter','none')% desable tex interpreter
    411451    end
     
    445485        set(htitle,'Interpreter','none')% desable tex interpreter
    446486    end
    447     % A REPRENDRE Mean
    448 %         hlist=findobj(gcf,'Style','listbox','Tag','liststat');
    449 %         if isempty(hlist)
    450 %             'text'
    451 %             textmean
    452 %             set(gca,'position',[0.13,0.2,0.775,0.73])
    453 %             uicontrol('Style','popupmenu','Position',[20 20 200 20],'String',textmean,'Tag','liststat');
    454 %         else
    455 %             set(hlist(1),'String',textmean)
    456 %         end
    457487end
    458488
    459489
    460490%-------------------------------------------------------------------
    461 function [AxeData,haxes,PlotParamOut,PlotType,errormsg]=plot_plane(Data,CellVarIndex,VarTypeCell,haxes,PlotParam,htext,PosColorbar)
     491function [haxes,PlotParamOut,PlotType,errormsg]=plot_plane(Data,CellVarIndex,VarTypeCell,haxes,PlotParam,PosColorbar)
    462492%-------------------------------------------------------------------
    463493
     
    478508hcol=findobj(hfig,'Tag','Colorbar'); %look for colorbar axes
    479509hima=findobj(haxes,'Tag','ima');% search existing image in the current axes
    480 AxeData=get(haxes,'UserData'); %default
    481 if ~isstruct(AxeData)% AxeData must be a structure
    482     AxeData=[];
    483 end
    484 AxeData.NbDim=2;
     510% AxeData=get(haxes,'UserData'); %default
     511% if ~isstruct(AxeData)% AxeData must be a structure
     512%     AxeData=[];
     513% end
     514% AxeData.NbDim=2;
    485515% if isfield(Data,'ObjectCoord')
    486516%     AxeData.ObjectCoord=Data.ObjectCoord;
     
    816846            end
    817847            set(hima,'Tag','ima','HitTest','off')
    818             set(haxes,'Tag',tag);%preserve the axes tag (removed by image fct !!!)           
     848            set(haxes,'Tag',tag);%preserve the axes tag (removed by image fct !!!)     
     849            uistack(hima, 'bottom')
    819850        % update an existing image
    820851        else
     
    831862        end
    832863    end
    833     if ~isstruct(AxeData)
    834         AxeData=[];
    835     end
     864%     if ~isstruct(AxeData)
     865%         AxeData=[];
     866%     end
    836867    test_ima=1;
    837868   
     
    885916       delete(hcol)
    886917    end
    887 %     AxeData.A=[];
    888 %     AxeData.AX=[];
    889 %     AxeData.AY=[];
    890918    PlotParamOut=rmfield(PlotParamOut,'Scalar');
    891919end
     
    902930    vec_V=reshape(vec_V,1,numel(vec_V));
    903931     MinMaxX=max(vec_X)-min(vec_X);
    904 %     MinMaxY=max(vec_Y)-min(vec_Y);
    905 %     AxeData.Mesh=sqrt((MinMaxX*MinMaxY)/length(vec_X));
    906932    if  ~isfield(PlotParam.Vectors,'AutoVec') || isequal(PlotParam.Vectors.AutoVec,0)|| ~isfield(PlotParam.Vectors,'VecScale')...
    907933               ||isempty(PlotParam.Vectors.VecScale)||~isa(PlotParam.Vectors.VecScale,'double') %automatic vector scale
    908934%         scale=[];
    909935        if test_false %remove false vectors
    910             indsel=find(AxeData.FF==0);%indsel =indices of good vectors
     936            %indsel=find(AxeData.FF==0);%indsel =indices of good vectors
    911937        else     
    912938            indsel=1:numel(vec_X);%
     
    10021028
    10031029%store the coordinate extrema occupied by the field
    1004 test_lim=0;
    1005 if test_vec
    1006     Xlim=[min(vec_X) max(vec_X)];
    1007     Ylim=[min(vec_Y) max(vec_Y)];
    1008     test_lim=1;
    1009     if test_ima%both background image and vectors coexist, take the wider bound
    1010         Xlim(1)=min(AX(1),Xlim(1));
    1011         Xlim(2)=max(AX(end),Xlim(2));
    1012         Ylim(1)=min(AY(end),Ylim(1));
    1013         Ylim(2)=max(AY(1),Ylim(2));
    1014     end
    1015 elseif test_ima %only image plot
    1016     Xlim(1)=min(AX(1),AX(end));
    1017     Xlim(2)=max(AX(1),AX(end));
    1018     Ylim(1)=min(AY(1),AY(end));
    1019     Ylim(2)=max(AY(1),AY(end));
    1020     test_lim=1;
    1021 end
    1022 AxeData.RangeX=Xlim;
    1023 AxeData.RangeY=Ylim;
    1024 % adjust the size of the plot to include the whole field, except if PlotParam.FixedLimits=1
    1025 if ~(isfield(PlotParam,'FixedLimits') && PlotParam.FixedLimits) && test_lim
    1026         if Xlim(2)>Xlim(1)
    1027             set(haxes,'XLim',Xlim);% set x limits of frame in axes coordinates
    1028         end
    1029         if Ylim(2)>Ylim(1)
    1030             set(haxes,'YLim',Ylim);% set y limits of frame in axes coordinate
    1031         end
    1032 end
    1033 if ~(isfield(PlotParam,'Auto_xy') && isequal(PlotParam.Auto_xy,1))
    1034      set(haxes,'DataAspectRatio',[1 1 1])
    1035 end
    1036 set(haxes,'YDir','normal')
    1037 set(get(haxes,'XLabel'),'String',[XName ' (' x_units ')']);
    1038 set(get(haxes,'YLabel'),'String',[YName ' (' y_units ')']);
    1039 PlotParamOut.x_units=x_units;
    1040 PlotParamOut.y_units=y_units;
    1041 
     1030if ~isempty(Data)
     1031    test_lim=0;
     1032    if test_vec
     1033        Xlim=[min(vec_X) max(vec_X)];
     1034        Ylim=[min(vec_Y) max(vec_Y)];
     1035        test_lim=1;
     1036        if test_ima%both background image and vectors coexist, take the wider bound
     1037            Xlim(1)=min(AX(1),Xlim(1));
     1038            Xlim(2)=max(AX(end),Xlim(2));
     1039            Ylim(1)=min(AY(end),Ylim(1));
     1040            Ylim(2)=max(AY(1),Ylim(2));
     1041        end
     1042    elseif test_ima %only image plot
     1043        Xlim(1)=min(AX(1),AX(end));
     1044        Xlim(2)=max(AX(1),AX(end));
     1045        Ylim(1)=min(AY(1),AY(end));
     1046        Ylim(2)=max(AY(1),AY(end));
     1047        test_lim=1;
     1048    end
     1049    AxeData.RangeX=Xlim;
     1050    AxeData.RangeY=Ylim;
     1051%    adjust the size of the plot to include the whole field, except if PlotParam.FixedLimits=1
     1052    if ~(isfield(PlotParam,'FixedLimits') && PlotParam.FixedLimits) && test_lim
     1053            if Xlim(2)>Xlim(1)
     1054                set(haxes,'XLim',Xlim);% set x limits of frame in axes coordinates
     1055            end
     1056            if Ylim(2)>Ylim(1)
     1057                set(haxes,'YLim',Ylim);% set y limits of frame in axes coordinate
     1058            end
     1059    end
     1060    if ~(isfield(PlotParam,'Auto_xy') && isequal(PlotParam.Auto_xy,1))
     1061         set(haxes,'DataAspectRatio',[1 1 1])
     1062    end
     1063    set(haxes,'YDir','normal')
     1064    set(get(haxes,'XLabel'),'String',[XName ' (' x_units ')']);
     1065    set(get(haxes,'YLabel'),'String',[YName ' (' y_units ')']);
     1066    PlotParamOut.x_units=x_units;
     1067    PlotParamOut.y_units=y_units;
     1068end
    10421069%-------------------------------------------------------------------
    10431070% --- function for plotting vectors
Note: See TracChangeset for help on using the changeset viewer.