MATLAB: How to create new .txt files named like the saved models in a folder and show Diag. View. information of each model in these files seperately

diagnostic viewersimulinktxt file

Hello people,
i am stuck with the following code, because I can't create new txt files by naming them as same as name of my saved Simulink models in the same folder. Besides I want the code to write the whole information from Diagnostic Viewer to these txt files due to consistency between model's name and txt file's name separately.
F.e. Simulation1.txt about Simulation1.slx
Simulation2.txt about Simulation2.slx etc.
Also I hope that you can help me for it.
Thank you very much in advance!
PATH = 'C:\Users\xxx\Documents\Saved_Models';
TxtFiles = fullfile(PATH, '*.txt');
allTxtFiles = dir(TxtFiles);
for i=1:nFiles
%Codes for simulation run
%---%
handles.txtFilename = allTxtFiles(i).name;
Filename = fullfile(PATH, handles.txtFilename);
fid = fopen(Filename);
%sprintf('Simulation%d.txt', i);
sldiagviewer.diary(handles.txtFilename);
end

Best Answer

Oh, probably more nearly what you're looking for would be something otoo--
PATH = 'C:\Users\xxx\Documents\Saved_Models';
dSlx = dir(fullfile(PATH, '*.slx'));
for i=1:numel(dSlx)
txtFname=fullfile(PATH,strrep(dSlx(i).name,'.slx','.txt'));
...
From there on, the above caveats are in place...