function MinEnergyDataArray = analyzeGSWavefunction_constrained_optimal_system_size(folder_path, LatticeSpacing)
    
    % Initialize matrix to store [Lx, Ly, minEnergy]
    MinEnergyDataArray = [];
    
    % Get a list of all subfolders in the parent folder
    subfolders = dir(fullfile(folder_path, 'Run_*'));
    
    % Loop through each subfolder
    for i = 1:length(subfolders)
        % Get the full path of the current subfolder
        subfolder_path = fullfile(subfolders(i).folder, subfolders(i).name);
        
        % Check if the current item is a folder
        if subfolders(i).isdir
            % Load the data file from the current folder
            data_file = fullfile(subfolder_path, 'psi_gs.mat');
            if isfile(data_file)
                % Load required variables from the .mat file
                Data = load(data_file, 'Params', 'VParams');
                
                % Extract Lx and Ly from Params.Dimensions
                Lx = Data.Params.Lx;
                Ly = Data.Params.Ly;
                
                % Extract the minimum energy from VParams.E_vs_iter
                try
                    minEnergy = min(gather(Data.VParams.E_vs_iter));
                catch
                    minEnergy = NaN;
                end
                
                % Append [Lx, Ly, minEnergy] to the results array
                MinEnergyDataArray(end + 1, :) = [Lx, Ly, minEnergy];
            else
                fprintf('Warning: File psi_gs.mat not found in %s\n', subfolder_path);
            end
        end
    end
    
    % Initialize arrays to store values
    Lx_Range            = zeros(1, length(LatticeSpacing));
    Ly_Range            = zeros(1, length(LatticeSpacing));
    MinEnergyDataValues = zeros(1, length(LatticeSpacing));
    
    % Loop through the values of LatticeSpacing
    for i = 1:length(LatticeSpacing)
        a = LatticeSpacing(i);
        % Calculate Lx and Ly based on the given conditions
        lx = a;
        ly = sqrt(3) * a;
        for idx                          = 1:size(MinEnergyDataArray, 1)
            Lx                           = MinEnergyDataArray(idx, 1);
            Ly                           = MinEnergyDataArray(idx, 2);
            energy                       = MinEnergyDataArray(idx, 3);
            tolerance                    = 1e-10;  % Define a small tolerance
            if (abs(Lx - lx) < tolerance) && (abs(Ly - ly) < tolerance)
                Lx_Range(i)            = Lx;  
                Ly_Range(i)            = Ly;
                MinEnergyDataValues(i) = energy;
            elseif MinEnergyDataValues(i)==0 || isnan(MinEnergyDataValues(i))
                Lx_Range(i)            = NaN;  
                Ly_Range(i)            = NaN;
                MinEnergyDataValues(i) = NaN;
            end
        end
    end

    figure
    clf
    set(gcf,'Position',[50 50 950 750])
    set(gca,'FontSize',16,'Box','On','Linewidth',2);
    plot(LatticeSpacing, MinEnergyDataValues, LineStyle='none', Marker = "o", MarkerFaceColor= "b", MarkerEdgeColor="none", LineWidth=2.0);
    xlim([min(LatticeSpacing) max(LatticeSpacing)])
    xlabel('$a$','fontsize',16,'interpreter','latex');
    ylabel('$E_{var}$','fontsize',16,'interpreter','latex');
    title('Minimum variational energy for different (constrained) unit cell sizes', 'FontSize', 16);
    grid on
end
