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?

조회 수: 1 (최근 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
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
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
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.
OK
OK 2019년 8월 7일
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!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by