How can I get signal dimensions in Simulink model

风格不统一 提交于 2019-12-09 01:02:15

问题


I have a question.

After simulate a simulink model I need to get signal dimensions of each line using MATLAB command.

I get line handles by following

line_h = find_system(gcs, 'FindAll', 'on','SearchDepth', 1, 'Type', 'Line')

then how can I get signal dimensions from line handles

** When check 'signal dimensions' in Format menu -> Port/Signal Displays After simulate a model number of signal dimensions will show on nonscalar line. I need to get it using MATLAB command.

Sorry for my English skill

Thank you


回答1:


If you have a set of line handles from your find_system command you can use the following command to get the block connected to the signal.

hblkSrc = get_param(h(k),'SrcBlockHandle');

You can then use get_param(hblkSrc,'CompiledPortDimensions') as suggested by am304 to get the dimensions.




回答2:


Alternatively, you can find the signal dimensions and signal widths of each block they originate from, using:

get_param(<block_path>,'CompiledPortDimensions')
get_param(<block_path>,'CompiledPortWidths')

Replacing <block_path> with the appropriate block path for each block of interest. The model must be compiled before you can run these commands, but since you indicate doing this after running the model, that shouldn't be a problem.




回答3:


You can solve it the following way.

  1. Enable signal logging for the desired signals (Properties). For example set the name to custom and signalone.
  2. If you actually don't want to log the signal, set Limit data points to last to 1, so you avoid storing unused data.
  3. Go to SImulink preferences and enable signal logging, default output name is logsout
  4. after simulation you'll get a dataset logsout in your workspace

now evaluate this dataset as follows:

% returns data, if data limit is set to 1 it's a coloumn 
% vector with just the last value
data = logsout.get('signalone').Values.Data

you can now just use the size of this vector and you know the dimension of the signal

[~,dim]=size(data)

or in one line:

[~,dim]=size(logsout.get('signalone').Values.Data)

If you have a a lot of signals and you want to evaluate them at once, give your signals convenient output-names and use a loop for iterating through a string vector with all your signal names.

As you say you want the dimensions of "all" (are you sure?) signals I think it is more convenient to just check "Enable signal logging" in each signal property and do all further definitions in the Simulink preferences where you have a list to manage all signals.



来源:https://stackoverflow.com/questions/19176680/how-can-i-get-signal-dimensions-in-simulink-model

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!