フィルターのクリア

How to save and update a simulink model via code?

4 ビュー (過去 30 日間)
Deon Hargrove
Deon Hargrove 2020 年 4 月 27 日
編集済み: Deon Hargrove 2020 年 4 月 27 日
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
Ameer Hamza 2020 年 4 月 27 日
You already have the lines
set_param(gcs,'SimulationCommand','Update');
save_system(system);
Are you getting any error?
Deon Hargrove
Deon Hargrove 2020 年 4 月 27 日
編集済み: Deon Hargrove 2020 年 4 月 27 日
No I am not, but I still have to manually save and update the model. For some reason the commands are not be activated or I am not using them correctly.
Update: I am not geeting this error
The specified top model was not saved due to the existence of dirty referenced models (for example,
'lm6Core/parameters'). Use the save_system name-value pair 'SaveDirtyReferencedModels','on' to
save the specified top model as well as all the dirty referenced models.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeProgrammatic Model Editing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by