How can I get signal dimensions in Simulink model

前端 未结 3 1393
梦谈多话
梦谈多话 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.

提交回复
热议问题