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?

2 visualizaciones (últimos 30 días)
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
  1 comentario
dpb
dpb el 3 de Ag. de 2019
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;
...
nFiles isn't defined...???? Whassup w/ that?
nFiles=numel(allTxtFiles);
I don't see any point in creating a struct handles; why not just use the returned file name as is?
I "know nuthink!" about Simulink as far as the other question whatever the diary procedure does and whether it can take a filename or needs a file handle or whether it can even do anything beyond writing to console you'll have to research the doc to see...

Iniciar sesión para comentar.

Respuesta aceptada

dpb
dpb el 3 de Ag. de 2019
Editada: dpb el 3 de Ag. de 2019
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...
  5 comentarios
dpb
dpb el 4 de Ag. de 2019
Editada: dpb el 5 de Ag. de 2019
Well, reading the documentation, looks like that would be pretty-much the expected result...read that page and example code carefully...in particular note the following comment:
...
sldiagviewer.diary('off') % Switch off logging.
open_system('sldemo_fuelsys') % Any operation you do after the previous command will not be logged
rtwbuild('sldemo_fuelsys')
sldiagviewer.diary('on') % Resume logging in the previously specified log file.
The state is a toggle -- if it was on, a filename turns it off and vice versa. I'm guessing you need to look carefully at the sequence and if it is the sim(mdl) command that runs the model that you want logged, then that isn't going to be logged because you would need the .diary command before the sim(mdl) statement. Consequently, since it follows, looks like your text/logging files will always be one behind the actual. Which, if I interpret the comment correctly, is what you're seeing.
OK
OK el 7 de Ag. de 2019
I made it by rewriting it:
...
sldiagviewer.diary('off');
open_system(x);
f = open('GUI.fig');
figure(f);
sim(x);
sldiagviewer.diary('on');
sldiagviewer.diary(strrep(x,'.slx','.txt'));
close_system(x);
...
If you realized I wrote .diary('off') before open_system and .diary('on') after sim(x) and before .diary(strrep...). Also it is COMPLETELY done what I exactly want. Thank you again for your help!!!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Naming Conventions en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by