how to get the path of a .ssc file that relates to your block built by ssc_build.

조회 수: 5 (최근 30일)
I have a simscape block built using a .ssc file. Both have different names "Block source" and "source.ssc". I would like to know if it is possible to get the source code path from the block. Through code in matlab. I know it is possible by selecting 'source code' in the dialog window of the block but I would like to do it with code. I have also seen that there are toolboxes that could help me, but I want to avoid using them, since I can only use the trial version.

채택된 답변

Manoj Mirge
Manoj Mirge 2023년 4월 18일
Hi Paola,
Since the Simscape Component block is general block in your Simulink model, you can use get_param function in your Matlab script to get mask properties of your Simscape Component block. The mask of Simscape Component block will have property named “ComponentPath” which will have value as path of .ssc file used for building corresponding Simscape Component block. After getting path of your .ssc file you can open that file using Matlab script and have access to the source code.
In your case the code you will have to write might look like this:
% If your Similink model name is ‘MyModel’
%If your block’s path is “ MyModel/Block source“
load_system("MyModel")
a=get_param("MyModel/Block source","MaskWSVariables");
% "MaskWSVariables" parameter will have mask variables of your block
% 'a' will be struct array with fileds of Name and Value.
% You can check in struct array ‘a’ to find struct which has Name field of ‘ComponentPath’ and corresponding to that find Value field of that struct.
% variable that will store path of .ssc file
pathofsscfile;
for i=1:length(a)
if a(i).Name=='ComponentPath'
pathofsscfile=a(i).Value;
end
end
You can read more about get_param function here.
You can read more about Mask variables of block here.
Hope this helps.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Composite Components에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by