digged a bit further but do not know howto execute "Collapse All" programatically
Otherwise this code could do what I want
function CollapseCurrentScriptLikeFoldInitially()
%% temporary set CodeFolding Preferences like "Fold Initially" Selection
s = settings;
% get Code Folding Preferences
CF = s.matlab.editor.codefolding;
% rearrange Preferences
fn = fieldnames(CF);
fn = sort(fn);
indInit = contains(fn,'Initially');
fnInit = fn(indInit);    % "Fold Initially" 
fn     = fn(~indInit) ;  % "Enabled"
TF     = {'o','x'};      % TrueFalse for display
for n = 1:length(fn)
    fni = fn{n};
    myInd = contains(fnInit,fni); % finds the corresponding "Fold Initially" 
    if any(myInd)
        fprintf('%30s: %s  %s\n', fni, TF{CF.(fni).ActiveValue+1}, TF{CF.(fnInit{myInd}).ActiveValue+1});
        CF.(fni).TemporaryValue = CF.(fnInit{myInd}).ActiveValue;
    else
        fprintf('%30s: %s\n', fni, TF{CF.(fni).ActiveValue+1});
    end
end
%% call KeyStroke "Collapse All"
warning(sprintf('This section does not work!\nNeeded to be replaced by a "CollapseAll" command. :-('))
import java.awt.Robot;
import java.awt.event.*;
RoboKey = Robot;
RoboKey.keyPress(KeyEvent.VK_CONTROL);
RoboKey.keyPress(KeyEvent.VK_COMMA);
RoboKey.keyRelease(KeyEvent.VK_CONTROL);
RoboKey.keyRelease(KeyEvent.VK_COMMA);
% https://stackoverflow.com/questions/25994261/how-to-execute-collapse-all-folds-in-the-matlab-editor-programatically
%% reset code CodeFolding Preferences 
for n = 1:length(fn)
    fni = fn{n};
    if hasTemporaryValue(CF.(fni))
        clearTemporaryValue(CF.(fni))
    end
end
end


