The "CompiledPortDimensions" attribute is different because for a bus connected to a top-level Outport, there is no equivalent of a virtual bus in C/C++ when it comes to code generation. So the signal needs to be interpreted as a muxed signal (a vector), which would be an array for C/C++ code. Thus, "CompiledPortDimensions" gives you the correct information about how the signal is interpreted in the generated code.
To retain the long format used for virtual buses, you can try one of the following ways:
Option 1: Temporarily disconnect the virtual bus from the top-level Outport and then query "CompiledPortDimensions" for the block which outputs the bus signal. For an example, please open the subsystem in the attached model and then run the attached script.
Option 2: The recommended workflow is to assign a bus object to the top-level Outport to ensure that the output is indeed interpreted as a Bus. The bus would now be a struct in the generated code.
To programmatically get the dimensions of the signals contained in the bus object, select the Outport in Simulink and execute the commands below in MATLAB. This will create a cell array 'Dimension', with each cell containing the dimensions of the corresponding bus element.
>> temp = get_param(gcb, 'CompiledPortDataTypes');
>> name_cell = temp.Inport;
>> name = name_cell{1};
>> BusElementArray = eval([name '.Elements']);
>> for i=1:numel(BusElementArray)
>> temp = BusElementArray(i);
>> Dimension{i} = temp.Dimensions;
>> end
Best Answer