I found the error. I simply have the change the first line to:
function [XTrain, YTrain, layers, options] = Experiment1_setup3(params)
For optimization of the XTest prediction i had to create a new function following this example https://de.mathworks.com/help/deeplearning/ug/experiment-using-bayesian-optimization.html
I found it untypically difficult for Matlab to find the correct information on this matter.