3
votes

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

3

3 Answers

3
votes

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.

2
votes

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.

2
votes

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.