MATLAB: Function handle to matlab system / function file using code

code generationMATLABmatlab functionscriptsimulink

Hi all,
I want to use a Matlab System or Matlab Function block in Simulink with one single equation.
After some calculations during simulink init, I obtain a function handle T = @(phi,phi_d,phi_dd). I now want to "copy" this function 'automatically' (i.e. using code) to the Matlab System file.
I realy need the automated soultion, but I have no idea how to change or generate m-files using code.
thanks for your help!

Best Answer

solved myself:
line1 = 'functionhead'
line2 = strcat(' T = ',func_str,';');
line3 = 'end'
Fid = fopen('filename.m','w');
fprintf(Fid, '%s\n\n%s\n\n%s', line1,line2,line3),
fclose(Fid);