function make_variation_plot()
%MAKE_VARIATION_PLOT Add a paper-style learning-curve figure to each variation.
%   MAKE_VARIATION_PLOT() copies variation_plot.m into every variations/<name>/
%   folder with a data.csv (as plotcurve.m) and runs it, producing
%   learning_curve.png (mean +/- SEM successes per training day, anodal red vs
%   control blue). Re-runnable; picks up new folders.

thisDir = fileparts(mfilename('fullpath'));
template = fullfile(thisDir, 'variation_plot.m');
root = fullfile(thisDir, 'variations');

d = dir(root);
n = 0;
for i = 1:numel(d)
    if ~d(i).isdir || ismember(d(i).name, {'.', '..'}); continue; end
    folder = fullfile(root, d(i).name);
    if ~exist(fullfile(folder, 'data.csv'), 'file'); continue; end
    copyfile(template, fullfile(folder, 'plotcurve.m'));
    localRun(fullfile(folder, 'plotcurve.m'));
    n = n + 1;
end
fprintf('\nAdded plotcurve.m + learning_curve.png to %d variation folders.\n', n);

end

function localRun(scriptPath)
run(scriptPath);
end
