I have a Simulink model I created that executes a dynamic model of a hydraulic motor. The dynamic model was originally developed using MATLAB code that uses structures as inputs and outputs to make passing parameters and results much more compact and logical. I've embedded the functions in Simulink using the "MATLAB Function" block.
Following the example in "emldemo_bus_struct", I've converted my input and output structures into buses that have the same organizational structure as the original data structures I was using. This works for all but one of the outputs.
The model is set-up to be able to use a variable number of pistons, and return the results for each piston by resizing an array accordingly. To be able to take advantage of the variable time step solvers in Simulink, I set the "DimensionsMode" of each bus element to "Fixed" and programatically update the dimensions of the bus element before running the Simulink model. The number of pistons is constant for a given run of the model. I can perform the analysis as desired, but when trying to assign the results to the output structure/bus, I get the error "Dimension 1 of field 's' is fixed on the left-hand side but varies on the right ([11 x 1] ~= [:? x 1])." I understand that this error occurs because the size of the array within the function is technically variable, even though the same parameter is used to set both the size of the bus element and the size of the calculation within the function.
Because the underlying analysis is performed using MATLAB code that is used elsewhere, I can't hard-code the number of pistons into the MATLAB function. Additionally, we run the analysis with a different number of pistons on occasion, so having hard-coded values are non-ideal.
I have already tried putting the line "coder.varsize('s');" before preallocating space for the results, but that did not work.
Ultimately, I'd like to be able to force Simulink to ignore checking that the size on the right-hand side (the calculation results) is the same as the left-hand side (the bus), because I know they will be the same size.
Any help on this issue would be greatly appreciated.