Is there a way to get a signals properties in Matlab?

조회 수: 5 (최근 30일)
Brandon1363
Brandon1363 2016년 7월 28일
답변: Satishkumar Aruljothi 2016년 8월 2일
Hello, I need to pull a signals data type as its shown in the properties below. Is there a way for me get this information using get_param or another function?
Thanks!
Signal with properties:
CoderInfo: [1x1 Simulink.CoderInfo]
Description: 'PCC Set speed offset converted to fixed point'
DataType: 'fixdt(1,16,0.100000,-0.000000)'
Min: -125
Max: 125.9960
DocUnits: 'KmPh'
Dimensions: -1
DimensionsMode: 'auto'
Complexity: 'real'
SampleTime: -1
SamplingMode: 'auto'
InitialValue: ''

답변 (2개)

Shameer Parmar
Shameer Parmar 2016년 7월 29일
It looks like you want to access the datatype of signals added into your BaseWorkSpace.
Lets consider if signal "a", "b", "c" are added into BaseWorkSpace then, Simply you can do this..
listOfSignals = who;
ListOfDataType = {'Signal Names', 'DataType'};
for i=2:length(listOfSignals)+1
ListOfDataType{i,1} = listOfSignals{i-1};
ListOfDataType{i,2} = eval([listOfSignals{i-1},'.DataType']);
end
To check the list of DatatType.. Type this..
ListOfDataType
OutPut will be..
ListOfDataType =
'Signal Names' 'DataType'
'a' 'auto'
'b' 'boolean'
'c' 'fixdt(1,16,0.100000,-0.000000)'
Please Note:
1. While running this code.. make sure, only Simulink Signals\Parameters are present in your Base Workspace.. if your BaseWorkSpace contains any other type of dataobjects, (which dont have the property called 'DataType') then it may cause an error.. So to resolve such error, you may have to apply such if condition under this For Loop...
2. If you have dont have Signals present in BaseWorkSpace OR different Requirement, then this code will not work.. So let me know your requirement in details, like, from where you accessing these Signals ?
  댓글 수: 2
Brandon1363
Brandon1363 2016년 7월 29일
편집: Brandon1363 2016년 7월 29일
Unfortunately my Base Workspace has different types of data objects that do not have the property called 'DataType'. So I am getting an error. I am pulling these signals from a Simulink model in order to set annotations for specific blocks, based on their data type information. I'm only dealing with one signal at a time.
Shameer Parmar
Shameer Parmar 2016년 8월 1일
Ok.. So how you pulling the signals from your model.. Because the Data (properties) you pasted in your question only get if you added signal in your Base WorkSpace.. The signal data (properties) you pasted in your question shows that, it is present in Base WorkSpace as Simulink.Signals... Only when it shows these properties..like Description, Min, Max, CoderInfo, Complexity etc etc..
So please confirm on how you got these signal properties from your model then may be I can help you..

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


Satishkumar Aruljothi
Satishkumar Aruljothi 2016년 8월 2일
I think you are trying to retrieve 'data type' from CSC type variable.
you can simply use variable_name.DataType.
>> Myvariable1
Myvariable1 = Properties: Value: 2000 CoderInfo: [1x1 Simulink.CoderInfo] Description: 'maximum allowed ' DataType: 'fixdt(0,8,10,0)' Min: [] Max: [] DocUnits: '' Complexity: 'real' Dimensions: [1 1]
>> Myvariable1.DataType
ans =
fixdt(0,8,10,0)

카테고리

Help CenterFile Exchange에서 Signal Attributes and Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by