www.gusucode.com > simulinktest 案例源码程序 matlab代码 > simulinktest/CloneAndExportTestHarnessExample.m

    %% Clone and Export a Test Harness to a Separate Model
% This example demonstrates cloning an existing test harness and exporting
% the cloned harness to a separate model. This can be useful if you want to
% create a copy of a test harness as a separate model, but leave the test
% harness associated with the model component.

%% High-level Workflow
%
% # If you don't know the exact properties of the test harness you want to
% clone, get them using sltest.harness.find. You need the harness owner ID
% and the harness name.
% # Clone the test harness using sltest.harness.clone.
% # Export the test harness to a separate model using
% sltest.harness.export. Note that there is no association between the
% exported model and the original model. The exported model stands alone.

%% Open the Model and Save a Local Copy
%
model = 'sltestTestSequenceExample';
open_system(model)

%%
%
% Save the local copy in a writable location on the MATLAB path.

%% Get the Properties of the Source Test Harness
%
properties = sltest.harness.find([model '/shift_controller'])

%% Clone the Test Harness
%
% Clone the test harness using sltest.harness.clone, the |ownerFullPath|
% and the |name| fields of the harness properties structure.
%
%   sltest.harness.clone(properties.ownerFullPath,properties.name,'ControllerHarness2')

%% Save the Model
%
% Before exporting the harness, save changes to the model. 
%
%   save_system(model)

%% Export the Test Harness to a Separate Model
%
% Export the test harness using sltest.harness.export. The exported model
% name is |ControllerTestModel|.
%
%   sltest.harness.export([model '/shift_controller'],'ControllerHarness2',...
%       'Name','ControllerTestModel')

%%
clear('model')
clear('properties')
close_system('sltestTestSequenceExample',0)