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 次查看(过去 30 天)
显示 更早的评论
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 个评论
dpb
2019-8-3
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...
采纳的回答
dpb
2019-8-3
编辑:dpb
2019-8-3
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 个评论
dpb
2019-8-4
编辑:dpb
2019-8-5
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Naming Conventions 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!