How can I evaluate an Simulink.data.Expression in a MATLAB script
4 次查看(过去 30 天)
显示 更早的评论
Hi all,
In my data dictionary, I have a Simulink.Parameter whose value is set as an expression:
Parameter with properties:
Value: slexpr("single(420*pi/180)")
CoderInfo: [1×1 Simulink.CoderInfo]
Description: '...'
DataType: 'single'
Min: 0
Max: 20
Unit: 'rad'
Complexity: 'real'
Dimensions: [1 1]
Now I would like to get the numeric value of the parameter within a script. So how can I evaluate the expression
slexpr("single(420*pi/180)")
to get
ans =
single
7.3304
Any hint would be greatly appreciated. Thank you very much.
1 个评论
checker
2023-10-3
Assuming you have a variable set equal to the expression
parmVal = slexpr("single(420*pi/180")
it will be of class type 'Simulink.data.Expression'
The value can be determined by the following
parmVal=eval(parmVal.ExpressionString)
回答(1 个)
Jeffrey Clark
2022-9-15
@Karsten Gordon, Evaluate MATLAB expression in data dictionary section - MATLAB evalin (mathworks.com) or Evaluate MATLAB expression - MATLAB eval (mathworks.com). I don't have Simulink to try; to use the eval function you would have to use just what is in the quotes:"single(420*pi/180)"
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Identification 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!