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

6 次查看(过去 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 中查找有关 Creating Custom Components and Libraries 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by