Dimension Mismatch between Simulink Bus and Calculation Results
23 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Nate Fulbright
le 23 Mar 2020
Commenté : Nate Fulbright
le 6 Avr 2020
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.
0 commentaires
Réponse acceptée
Mark McBroom
le 4 Avr 2020
The easiest approach is to set the variable that holds the result to be a fixed length vector with a length equal to the largest number of pistons you expect to have. This is easier than trying to set up the MATLAB code for varsize, and in the end you have to set up varsize with the max possible length anyway ( Simulink only supports bounded varsize ).
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Sources dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!