hey assistent I have this codebase for l=1:4
    try
    for j=1:length(indCheckedVariable_Y(l,1:end))
        
        if indCheckedVariable_Y(l,j)>0
            
            for q=1:length(indChecked_atvehiclespeed)
                
                cla(hAxes);
                
                if l==4
                    %%%%%%%%% Cas d'affichage des variables Y en fonction de la
                    %%%%%%%%% vitesse
                    if Repet_perfo == 1
                        plotRepetPerfoReaccel([],[],hFigure,hAxes,data,0,0,{Idientif_VariableX(l),Idientif_VariableY(indCheckedVariable_Y(l,j)),22})
                    else
                        plotReaccel2PGraph([],[],hFigure,hAxes,data,0,0,{Idientif_VariableX(l),Idientif_VariableY(indCheckedVariable_Y(l,j)),22})
                    end    
                else
                    if Repet_perfo == 1
                        plotRepetPerfoReaccel([],[],hFigure,hAxes,data,0,0,{Idientif_VariableX(l),Idientif_VariableY(indCheckedVariable_Y(l,j)),Idientif_vehiclespeed(indChecked_atvehiclespeed(q))})
                    else
                        plotReaccel2PGraph([],[],hFigure,hAxes,data,0,0,{Idientif_VariableX(l),Idientif_VariableY(indCheckedVariable_Y(l,j)),Idientif_vehiclespeed(indChecked_atvehiclespeed(q))})
                    end   
                end
                
                warning off;
                
                hWait=helpdlg('Saving images   (please wait)','Loading data');
                set(findobj(hWait,'Style','pushButton'),'visible','off');
                pause(0.1);
                
                
                
                if isstr(nomRepertoire)
                    
                    hFigureLegend=findobj('Tag',[get(hFigure,'Tag') 'Legend' ]);
                    
                    % Print plot
                    set(hFigureLegend,'visible','off');
                    set(hFigure,'visible','off');
                    
                    hPanel = findobj(hFigure,'Type','uipanel');
                    for i = 1:length(hPanel)
                        hButtons = get(hPanel(i),'Children');
                        set([hPanel(i); hButtons],'Visible','off');
                    end
                    
                    if (l==1)
                        
                        nomFile=[char(VariableNAME(l,indCheckedVariable_Y(l,j))) '-' char(atvehiclespeed(indChecked_atvehiclespeed(q)))];
                        nomFile=[nomFile ' vs AccPdlTarget (X)'];
                    elseif (l==2)
                        
                        nomFile=[char(VariableNAME(l,indCheckedVariable_Y(l,j))) '-' char(atvehiclespeed(indChecked_atvehiclespeed(q)))];
                        nomFile=[nomFile ' vs t0_rel (X)'];
                    elseif (l==3)
                     
                        nomFile=[char(VariableNAME(l,indCheckedVariable_Y(l,j))) '-' char(atvehiclespeed(indChecked_atvehiclespeed(q)))];
                        nomFile=[nomFile ' vs SOC (X)'];
                        
                    elseif (l==4)
                        nomFile=[char(VariableNAME(l,indCheckedVariable_Y(l,j)))];
                        nomFile=[nomFile ' vs VhSpeed (X)'];
                    end
                    
                    if (l<4)
                    % Suppression du dossier de sauvegarde des fichiers découpés si existant
                    savePath=[nomRepertoire '\' char(atvehiclespeed(indChecked_atvehiclespeed(q))) 'kph'];
                    mkdir(savePath);
                    print(hFigure,'-dpng','-r350','-loose',fullfile(savePath,nomFile));
                    else
                    print(hFigure,'-dpng','-r350','-loose',fullfile(nomRepertoire,nomFile));
                    end
                    
                    for i = 1:length(hPanel)
                        hButtons = get(hPanel(i),'Children');
                        set([hPanel(i); hButtons],'Visible','on');
                    end
                    
                    
                    % Initialise legend data
                    data=getappdata(hFigure,'data');
                    iMeasure=getappdata(hFigure,'iMeasure');
                    
                    % Build name
                    [pathstr, nomFile, ext]=fileparts(fullfile(nomRepertoire,nomFile));
                    nomFile=[nomFile '_legend' ext ];
                    
                    % Plot & Print legend
                    if ~isempty(hFigureLegend)
                        
                        if (l<4)
                            print(hFigureLegend,'-dpng','-r350','-loose',fullfile(savePath,nomFile));
                        else
                            print(hFigureLegend,'-dpng','-r350','-loose',fullfile(nomRepertoire,nomFile));
                        end
                    end
                   
                    
                    % réaffichage
                    set(hFigure,'visible','on');
                    if ~isempty(hFigureLegend)
                        set(hFigureLegend,'visible','on');
                    end
                    
                  
                    delete(hWait);
                    
                    warning on;
                    
                end
                
            end
        end
    end
    catch err
        fprintf(err.message)
    end
    
end It works sometimes but sometimes dosen't for the same data. It mostlsy erros were hFigureLegend is used for example on that print, maybe is not selected or isn't focused and it errors evreything after