Fix bug where a plot is rendered on incorrect fig
authorLukáš Jiřiště <jiriste@icpf.cas.cz>
Tue, 30 Jul 2024 14:09:41 +0000 (16:09 +0200)
committerLukáš Jiřiště <jiriste@icpf.cas.cz>
Tue, 6 Aug 2024 09:57:43 +0000 (11:57 +0200)
I dont know whether Matlab can't keep up and does not keep track of
figures, but some figures had no plots and other figures had the missing
plots. This is (hopefully) fixed by directly telling imshow and plot
what figure (axes) to use.

Bubliny.m

index 2249ad20d498d24f380ee1a4a62778a967f63270..9534b11b416edb92996514f400f96b9af0d62d3b 100755 (executable)
--- a/Bubliny.m
+++ b/Bubliny.m
@@ -80,11 +80,11 @@ for iii=1:1:nSelectedDirectory  % Cycles for directories with files
                IntensitiesAverFin{jjj} = get_representative_intensities(ContrastFigure);\r
 \r
 % Figure with average intensity, without the bands with hole and meter\r
-               figure\r
-               imshow(ContrastFigure)\r
-               hold on\r
-               plot(IntensitiesAverFin{jjj},'-y','linewidth',2)\r
-               hold on\r
+               f = figure();\r
+               ax = axes(f);\r
+               imshow(ContrastFigure, 'Parent', ax)\r
+               hold(ax, 'on');\r
+               plot(ax, IntensitiesAverFin{jjj},'-y','linewidth',2)\r
                if jjj>=startFile+step                                                            %subtracts the intensities\r
                        plot(IntensitiesAverFin{jjj-step},'Color',[0.9290 0.6940 0.1250],'linewidth',2)\r
                        hold on\r
@@ -112,7 +112,7 @@ for iii=1:1:nSelectedDirectory  % Cycles for directories with files
                                [Height(1,jjj),pkH]=max(pk);\r
                                qH=lk(pkH);\r
                                Metr_fit_H(1,jjj)=polyval(polypar_Metr,qH);\r
-                               plot(qH,-Height(jjj),'or','linewidth',2)\r
+                               plot(ax, qH, -Height(jjj), 'or', 'linewidth', 2)\r
                        elseif jjj>=startFile+step\r
                                if waytrend<=0;\r
                                        [pk,lk] = findpeaks(-IntensitiesAverFin_2{jjj}(1:(LevelPixels+30)));  %10\r
@@ -124,7 +124,7 @@ for iii=1:1:nSelectedDirectory  % Cycles for directories with files
                                        qH=lk(pkH);\r
                                        Metr_fit_H(1,jjj)=polyval(polypar_Metr,qH);\r
                                end\r
-                               plot(qH,Height(jjj),'om','linewidth',2)\r
+                               plot(ax, qH, Height(jjj), 'om', 'linewidth', 2)\r
                        end\r
 \r
                elseif D_num==2\r
@@ -134,7 +134,7 @@ for iii=1:1:nSelectedDirectory  % Cycles for directories with files
                                [Height(1,jjj),pkH]=max(pk);\r
                                qH=LevelPixels+lk(pkH);\r
                                Metr_fit_H(1,jjj)=polyval(polypar_Metr,qH);\r
-                               plot(qH,-Height(jjj),'or','linewidth',2)\r
+                               plot(ax, qH, -Height(jjj), 'or', 'linewidth', 2)\r
                        elseif jjj>=startFile+step\r
                                if waytrend<=0;\r
                                        [pk,lk] = findpeaks(-IntensitiesAverFin_2{jjj}(LevelPixels:end));  %10\r
@@ -148,7 +148,7 @@ for iii=1:1:nSelectedDirectory  % Cycles for directories with files
                                        qH=NaN;\r
                                        Metr_fit_H(1,jjj)=NaN;\r
                                end\r
-                               plot(qH,Height(jjj),'om','linewidth',2)\r
+                               plot(ax, qH, Height(jjj), 'or', 'linewidth', 2)\r
                        end\r
                end\r
 \r
@@ -190,7 +190,7 @@ for iii=1:1:nSelectedDirectory  % Cycles for directories with files
                                Metr_fit_B(1,jjj)=NaN;                                                % For 1-4 files\r
                                qB=NaN;\r
                        end\r
-                       plot(qB,Bottom(jjj),'ob','linewidth',2)\r
+                       plot(ax, qB, Bottom(jjj), 'ob', 'linewidth', 2)\r
                else\r
                        if D_num==1\r
                                LevelPixels=MeterScale(1+(1000-LevelNum(1,jjj))/100);                 % x level in pixels in the original image\r
@@ -206,7 +206,7 @@ for iii=1:1:nSelectedDirectory  % Cycles for directories with files
                                        qB=NaN;\r
                                        Metr_fit_B(1,jjj)=NaN;\r
                                end\r
-                               plot(qB,Bottom(jjj),'oc','linewidth',2)\r
+                               plot(ax, qB, Bottom(jjj), 'oc', 'linewidth', 2)\r
                        elseif D_num==2\r
                                LevelPixels=MeterScale(1);                 % x level in pixels in the original image\r
                                if waytrend<=0;\r
@@ -221,7 +221,7 @@ for iii=1:1:nSelectedDirectory  % Cycles for directories with files
                                        qB=NaN;\r
                                        Metr_fit_B(1,jjj)=NaN;\r
                                end\r
-                               plot(qB,Bottom(jjj),'oc','linewidth',2)\r
+                               plot(ax, qB, Bottom(jjj), 'oc', 'linewidth', 2)\r
                        end\r
                end\r
 \r
@@ -232,7 +232,6 @@ for iii=1:1:nSelectedDirectory  % Cycles for directories with files
                clear ContrastFigure\r
                clear ContrastFigureFin\r
                % clear IntensitiesAverFin\r
-\r
        end  % jjj, Cycles for figures files\r
 \r
        hf4=figure ('Name','Velocity','NumberTitle','off','PaperSize',[8.5 6],'PaperUnits','centimeters');\r