% 如何将黑库仿真文件转换到新版MATLAB
%Specify the name of the original model you want to convert and open the model.
originalModelName = "myModelName";
open_system(originalModelName);
%To capture all relevant data during the simulation, add signal logging to all the scope inputs in the model. To find all Scope blocks in the model, use the find_system function and set the BlockType input argument to "Scope". Mark the input signals of these blocks for logging.
%If the original model does not contain any Scope blocks, to help confirm the conversion process, add Scope blocks to the model and connect them to signals of significant interest.

scopes = find_system(originalModelName,BlockType="Scope");
for scopeIdx = 1:height(scopes)
thisScope = scopes{scopeIdx};
lines = get_param(thisScope,"LineHandles");
lines = lines.Inport;
for lineIdx = 1:length(lines)
thisLine = lines(lineIdx);
Simulink.sdi.markSignalForStreaming(thisLine,"on");
end
end
%To retain these changes, save the updated model.
save_system(originalModelName);
%Log results by running a simulation of the original model.
sim(originalModelName);
%Use the spsConversionAssistant function to replace the Specialized Power Systems blocks in the model with Simscape Electrical blocks.
spsConversionAssistant(originalModelName);
%The function creates a new file named myModelName_simscape and saves it and the conversion HTML report in the current folder.
%Files pane containing the files generated by the spsConversionAssistant function. The first file is the HTML report, the second file is the converted model, and the third file is the original model.
%Review the HTML report, inspect replaced blocks for correctness, and manually convert unsupported blocks to Simscape and Simscape Electrical blocks.
%Open the converted model.
convertedModelName = originalModelName+"_simscape";
open_system(convertedModelName);
%Log results by running the converted Simscape model.
sim(convertedModelName);
%Compare the outputs of the original and converted models. This comparison helps you identify any discrepancies between the two sets of results. Consider setting the absolute and relative tolerances to values that make sense for your model.
absoluteTolerance = 1e-3;
relativeTolerance = 0.01;
timeTolerance = 1e-3;
runIDs = Simulink.sdi.getAllRunIDs;
runDiff = Simulink.sdi.compareRuns(runIDs(end-1,1),runIDs(end,1),...
abstol=absoluteTolerance,...
reltol=relativeTolerance,...
timetol=timeTolerance);
%Visualize the differences between the original and converted model outputs. The visualization shows the tolerances so you can observe if the differences are within these tolerances. This step provides a clear view of how the models compare and highlights any significant variations in their behavior.
Simulink.sdi.view(Simulink.sdi.GUITabType.CompareRuns);
%If the original and converted model outputs are considerably different, further investigate the model to determine whether the discrepancies are acceptable. If the differences occur at the start of the simulation, they might be caused by initialization differences. If you observe differences in other signals, review the HTML report to determine whether they result from converted blocks that are only partially supported.
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删