How to save and update a simulink model via code?
조회 수: 4 (최근 30일)
이전 댓글 표시
I am creating a function that checks simulink models for errors,reports them, and corrects them. I would like for the program to also be able to update and save the model once it has completed it tasks, How would I do that?
For example in this function the objective is to check testpoints lines and make sure the log data box is checked and the correct class is used. Once that is done I want it to update and save the model.
function testPointCheck( app )
%%%%%%App Specific Stuff
% stop the timer while we are running
stop(app.projectTimer);
% disable the generate button while we are running
%app.RunCleanupButton.Enable = 'off';
app.StatusArea.Value = 'Running test point check function. This can take awhile...';
filename = app.TopModelEditField.Value;
[folder, system, extension] = fileparts(filename);
load_system(system);
%%%%%%End App Specific Stuff
%Remove Old whitespace findings mat file
projects = slproject.getCurrentProjects;
projectRoot = projects.RootFolder;
saveFolder = [projectRoot '\scripts'];
saveFileFullName = [saveFolder '\testPoint.mat'];
warning('off','all')
delete (saveFileFullName);
%delete ('ErrorReport.xlsx');
%xlswrite('ErrorReport.xlsx','ErrorReport');
warning('on','all')
%allLines=find_system(system,'FindAll','on','type','line');
allLines = recursiveModelReferenceLines(char(getfullname(system)),[]);
testPointLines = [];
names = [];
%{
In this section the program is searching for lines with the test point
Box checked, stores them in a separate variable and retrieves their
name. After that the program corrects the errors
%}
for i=1:length(allLines)
point = get(allLines(i),'TestPoint');
if point ==1
testPointLines = vertcat(testPointLines,allLines(i));
%names =vertcat(names,get(testPointLines,'Name'));
cellarray =[get_param(testPointLines,'Parent') get(testPointLines,'Name')];
names = cellarray(:,2);
end
end
if (~isempty(names))
save(saveFileFullName,'testPointLines')
varName = {'Model','Line'};
for i=1:length(testPointLines)
unLoggedLines = get(testPointLines(i),'DataLogging');
Class = get(testPointLines(i),'StorageClass');
isClassGood = strcmp(Class, 'ExportedGlobal');
if unLoggedLines ==0
T = table(cellarray(:,1),cellarray(:,2),'VariableNames',varName);
writetable(T,'ErrorReport.xlsx','Sheet','unLoggedLines');
set(testPointLines(i),'DataLogging',1)
end
if isClassGood ==0
S = table(cellarray(:,1),cellarray(:,2),'VariableNames',varName);
writetable(S,'ErrorReport.xlsx','Sheet','incorrectStorageClass');
set(testPointLines(i),'StorageClass','ExportedGlobal')
end
end
set_param(gcs,'SimulationCommand','Update')
end
save_system(system);
end
댓글 수: 2
Ameer Hamza
2020년 4월 27일
You already have the lines
set_param(gcs,'SimulationCommand','Update');
save_system(system);
Are you getting any error?
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!