function [contrast_array, periodX_array, periodY_array] = analyzeGSWavefunction_multipleruns(folder_base_path, numberofruns) % Extract the last two folder names from folder_base_path folder_parts = strsplit(folder_base_path, '/'); if length(folder_parts) >= 2 video_name_base = strcat(folder_parts{end-1}, '_', folder_parts{end}); else video_name_base = folder_parts{end}; % In case there's only one folder in the path end % Create the output video name with .mp4 extension output_video_name = strcat(video_name_base, '_wavefunction_analysis.mp4'); % Initialize arrays to store contrast, periodX, and periodY for each run contrast_array = zeros(1, numberofruns); periodX_array = zeros(1, numberofruns); periodY_array = zeros(1, numberofruns); % Set up video writer videoObj = VideoWriter(output_video_name, 'MPEG-4'); % Create a video file object videoObj.FrameRate = 1; % Set the frame rate (adjust as needed) videoObj.Quality = 100; % Maximum quality (for compression) open(videoObj); % Open the video file for writing % Loop through all the runs and process each folder for run_index = 1:numberofruns % Call the function that processes the wavefunction data [contrast, periodX, periodY] = Scripts.analyzeGSWavefunction(folder_base_path, run_index); % Store the results in the arrays contrast_array(run_index) = contrast; periodX_array(run_index) = periodX; periodY_array(run_index) = periodY; % Capture the current figure (output of analyzeGSWavefunction_multipleruns) frame = getframe(gcf); % Get current figure as a frame writeVideo(videoObj, frame); % Write the frame to the video file % Optionally close the figure if you don't need it close(gcf); end % Close the video writer after all frames have been added close(videoObj); fprintf('Video saved as %s\n', output_video_name); % Return the arrays end