How can I get signal dimensions in Simulink model

前端 未结 3 1377
梦谈多话
梦谈多话 2021-01-06 13:07

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

<
相关标签:
3条回答
  • 2021-01-06 13:25

    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.

    0 讨论(0)
  • 2021-01-06 13:44

    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.

    0 讨论(0)
  • 2021-01-06 13:50

    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.

    0 讨论(0)
提交回复
热议问题