Move LevelNum out of the loop
authorLukáš Jiřiště <jiriste@icpf.cas.cz>
Wed, 31 Jul 2024 09:54:37 +0000 (11:54 +0200)
committerLukáš Jiřiště <jiriste@icpf.cas.cz>
Tue, 6 Aug 2024 12:49:21 +0000 (14:49 +0200)
As it is only read from the name of the directory, there are no changes
between iterations. LevelNum should eventually track the ACTUAL level.
When that time comes, it will be reintroduced to the loop as an array.

Bubliny.m

index 9534b11b416edb92996514f400f96b9af0d62d3b..ee11a3bc777ab32f314d3923d3af8cb8528c3bca 100755 (executable)
--- a/Bubliny.m
+++ b/Bubliny.m
@@ -50,10 +50,10 @@ for iii=1:1:nSelectedDirectory  % Cycles for directories with files
        FileName=([DirectoryName '/' SelectedDirectory{iii} '/' FileType]);\r
        FFiles = dir(FileName);                                                 % Loads files to struct FFiles(1).name, FFiles(1).folder, FFiles(1).date - i s casem\r
        nFFiles = numel(FFiles);                                                % Counts files\r
+       LevelNum=str2double(SelectedDirectory{iii}(7:9))*1000;\r
 \r
 %% variable allocation\r
 \r
-       LevelNum = zeros(1,nFFiles);\r
        Height = zeros(1,nFFiles);\r
        Metr_fit_H = zeros(1,nFFiles);\r
        Bottom = zeros(1,nFFiles);\r
@@ -101,12 +101,10 @@ for iii=1:1:nSelectedDirectory  % Cycles for directories with files
                Time(jjj)=duration([(ImageName(8:9)) ':' (ImageName(10:11)) ':' (ImageName(12:16))],'Format',infmt) - start_time;\r
                infmd = ['yy' 'MM' 'dd'];\r
                Date(jjj) = datetime(ImageName(1:6),'InputFormat',infmd);\r
-               Level(jjj,1:3)=SelectedDirectory{iii}(7:9);\r
-               LevelNum(1,jjj)=str2double(Level(jjj,:))*1000;\r
 \r
                % % plot(lk,abs(pk),'oc','linewidth',2)\r
                if D_num==1\r
-                       LevelPixels=MeterScale(1+(1000-LevelNum(1,jjj))/100);                 % x level in pixels in the original image\r
+                       LevelPixels=MeterScale(1+(1000-LevelNum)/100);                 % x level in pixels in the original image\r
                        if jjj<startFile+step\r
                                [pk,lk] = findpeaks(-IntensitiesAverFin{jjj}(1:(LevelPixels+30)));  %10\r
                                [Height(1,jjj),pkH]=max(pk);\r
@@ -193,7 +191,7 @@ for iii=1:1:nSelectedDirectory  % Cycles for directories with files
                        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
+                               LevelPixels=MeterScale(1+(1000-LevelNum)/100);                 % x level in pixels in the original image\r
                                if waytrend<=0;\r
                                        [pk2,lk2] = findpeaks(-IntensitiesAverFin_2{jjj}(LevelPixels:end));  %10\r
                                else\r
@@ -226,7 +224,7 @@ for iii=1:1:nSelectedDirectory  % Cycles for directories with files
                end\r
 \r
                writematrix(["ImageName" "Date" "Time [s]" "Intensities Height [-]" "Intensities Bottom [-]" "Height [cm]" "Bottom [cm]" "Level [cm]"], ResFile, "Sheet", SelectedDirectory{iii}, "Range", "A1:H1");\r
-               writematrix([ImageName string(Date(1,jjj)) seconds(Time(1,jjj)) Height(1,jjj) Bottom(1,jjj) Metr_fit_H(1,jjj) Metr_fit_B(1,jjj) str2double(SelectedDirectory{iii}(7:9))], ResFile, "Sheet", SelectedDirectory{iii}, "Range", ['A' num2str(jjj+1) ':H' num2str(jjj+1)]);\r
+               writematrix([ImageName string(Date(1,jjj)) seconds(Time(1,jjj)) Height(1,jjj) Bottom(1,jjj) Metr_fit_H(1,jjj) Metr_fit_B(1,jjj) LevelNum], ResFile, "Sheet", SelectedDirectory{iii}, "Range", ['A' num2str(jjj+1) ':H' num2str(jjj+1)]);\r
 \r
                clear Figure\r
                clear ContrastFigure\r
@@ -239,7 +237,7 @@ for iii=1:1:nSelectedDirectory  % Cycles for directories with files
        hold on\r
        hp2=plot(seconds(Time(startFile:step:end)), Metr_fit_B(startFile:step:nFFiles),'-ob','linewidth',2);\r
        hold on\r
-       hp3=plot(seconds(Time(startFile:step:end)),LevelNum(1,startFile:step:nFFiles)','-og','linewidth',2);\r
+       hp3=plot(seconds(Time(startFile:step:end)),LevelNum*ones(size(Time(startFile:step:end))),'-og','linewidth',2);\r
 \r
        xlabel('time [s]','FontWeight','bold');\r
        ylabel('position [cm]','FontWeight','bold');\r