From 9b8f4cc985bf36cbd3d63f86cb7be9f47972a86a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Luk=C3=A1=C5=A1=20Ji=C5=99i=C5=A1t=C4=9B?= Date: Tue, 30 Jul 2024 16:09:41 +0200 Subject: [PATCH] Fix bug where a plot is rendered on incorrect fig 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 | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/Bubliny.m b/Bubliny.m index 2249ad2..9534b11 100755 --- 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); % Figure with average intensity, without the bands with hole and meter - figure - imshow(ContrastFigure) - hold on - plot(IntensitiesAverFin{jjj},'-y','linewidth',2) - hold on + f = figure(); + ax = axes(f); + imshow(ContrastFigure, 'Parent', ax) + hold(ax, 'on'); + plot(ax, IntensitiesAverFin{jjj},'-y','linewidth',2) if jjj>=startFile+step %subtracts the intensities plot(IntensitiesAverFin{jjj-step},'Color',[0.9290 0.6940 0.1250],'linewidth',2) hold on @@ -112,7 +112,7 @@ for iii=1:1:nSelectedDirectory % Cycles for directories with files [Height(1,jjj),pkH]=max(pk); qH=lk(pkH); Metr_fit_H(1,jjj)=polyval(polypar_Metr,qH); - plot(qH,-Height(jjj),'or','linewidth',2) + plot(ax, qH, -Height(jjj), 'or', 'linewidth', 2) elseif jjj>=startFile+step if waytrend<=0; [pk,lk] = findpeaks(-IntensitiesAverFin_2{jjj}(1:(LevelPixels+30))); %10 @@ -124,7 +124,7 @@ for iii=1:1:nSelectedDirectory % Cycles for directories with files qH=lk(pkH); Metr_fit_H(1,jjj)=polyval(polypar_Metr,qH); end - plot(qH,Height(jjj),'om','linewidth',2) + plot(ax, qH, Height(jjj), 'om', 'linewidth', 2) end elseif D_num==2 @@ -134,7 +134,7 @@ for iii=1:1:nSelectedDirectory % Cycles for directories with files [Height(1,jjj),pkH]=max(pk); qH=LevelPixels+lk(pkH); Metr_fit_H(1,jjj)=polyval(polypar_Metr,qH); - plot(qH,-Height(jjj),'or','linewidth',2) + plot(ax, qH, -Height(jjj), 'or', 'linewidth', 2) elseif jjj>=startFile+step if waytrend<=0; [pk,lk] = findpeaks(-IntensitiesAverFin_2{jjj}(LevelPixels:end)); %10 @@ -148,7 +148,7 @@ for iii=1:1:nSelectedDirectory % Cycles for directories with files qH=NaN; Metr_fit_H(1,jjj)=NaN; end - plot(qH,Height(jjj),'om','linewidth',2) + plot(ax, qH, Height(jjj), 'or', 'linewidth', 2) end end @@ -190,7 +190,7 @@ for iii=1:1:nSelectedDirectory % Cycles for directories with files Metr_fit_B(1,jjj)=NaN; % For 1-4 files qB=NaN; end - plot(qB,Bottom(jjj),'ob','linewidth',2) + plot(ax, qB, Bottom(jjj), 'ob', 'linewidth', 2) else if D_num==1 LevelPixels=MeterScale(1+(1000-LevelNum(1,jjj))/100); % x level in pixels in the original image @@ -206,7 +206,7 @@ for iii=1:1:nSelectedDirectory % Cycles for directories with files qB=NaN; Metr_fit_B(1,jjj)=NaN; end - plot(qB,Bottom(jjj),'oc','linewidth',2) + plot(ax, qB, Bottom(jjj), 'oc', 'linewidth', 2) elseif D_num==2 LevelPixels=MeterScale(1); % x level in pixels in the original image if waytrend<=0; @@ -221,7 +221,7 @@ for iii=1:1:nSelectedDirectory % Cycles for directories with files qB=NaN; Metr_fit_B(1,jjj)=NaN; end - plot(qB,Bottom(jjj),'oc','linewidth',2) + plot(ax, qB, Bottom(jjj), 'oc', 'linewidth', 2) end end @@ -232,7 +232,6 @@ for iii=1:1:nSelectedDirectory % Cycles for directories with files clear ContrastFigure clear ContrastFigureFin % clear IntensitiesAverFin - end % jjj, Cycles for figures files hf4=figure ('Name','Velocity','NumberTitle','off','PaperSize',[8.5 6],'PaperUnits','centimeters'); -- 2.30.2