How to get string value from instances ?

조회 수: 2 (최근 30일)
Frédéric Schenker
Frédéric Schenker 2021년 8월 23일
댓글: Frédéric Schenker 2021년 9월 10일
Hello,
A stereotype contains a string property. I want to get the string value from this property when I perform an analysis with the instance of my system under analysis.
I use the command "getValue", but when I execute my script the following error appear :
Error using systemcomposer.analysis.AbstractInstanceElement/getValuePropertySetByName
Can't find value 'baseEnv' in set 'System_profile.stereotypeX'
Error in systemcomposer.analysis.AbstractInstanceElement/getValue
I can assure that the 'baseEnv' value exists. If I convert the 'baseEnv' property into a "double" value instead of a "string", the command pass without any problem. In addition, if I use the command "hasValue" with string property the result is False.
Do you have a solution for this problem ?
Thanks in adavance

채택된 답변

Josh Kahn
Josh Kahn 2021년 9월 7일
Hi Frédéric!
The System Composer Analysis function does not currently support string methods. A workaround is to operate on the Specification in your analysis function. The Specification is the element in your architecture model as opposed to the element that has been added to the analysis instantiation.
In 20b (note, this will return an empty string value if the property is not assigned):
function rollup(instance, varargin)
stereotypeProperty = 'SampleProfile.Stereotype1.StringProp1';
disp(instance.Name);
if isComponent(instance)
fprintf(" %s : %s\n", stereotypeProperty, getPropertyValue(instance.Specification, stereotypeProperty));
else
fprintf(" Not a component\n");
end
end
In 21a (with the introduction of the hasProperty method):
function rollup(instance, varargin)
stereotypeProperty = 'SampleProfile.Stereotype1.StringProp1';
disp(instance.Name);
if isComponent(instance)
if hasProperty(instance.Specification, stereotypeProperty)
fprintf(" %s : %s\n", stereotypeProperty, getPropertyValue(instance.Specification, stereotypeProperty));
else
fprintf(" Property '%s' not found\n", stereotypeProperty);
end
else
fprintf(" Not a component\n");
end
end
Regards,
Josh
  댓글 수: 1
Frédéric Schenker
Frédéric Schenker 2021년 9월 10일
Hi Josh,
Indeed your workaround works in my case (20b).
Thanks a lot for your support !
Regards,
Frédéric

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 System Composer에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by