Initialise a variable which changes sizer each iteration in simulink coder
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
How would i go about initialising a variable which changes size each iteration. I've tried three things to get past this
- The first being and i got that error which does make sense
powerout = zeros(1,1);
Attempted to access index 2 of an array with smaller dimension sizes. The valid index range is 1 to 1. This error will stop the simulation. In MATLAB Function 'ThermalBatterySimulinkModel/MATLAB Function': powerout(n) = SensiblePower;
- The second being this script of code for which i got this error
powerout = zeros(60,1);
Size mismatch (size [60 x 1] ~= size [1 x 1]). The size to the left is the size of the left-hand side of the assignment.
- The third being the following which i was not sure how this would work
powerout = zeros(1,1);
coder.varsize('powerout',[1 60]);
'powerout' is inferred as a variable-size matrix, but its size is specified as inherited or fixed. Verify 'powerout' is defined in terms of non-tunable parameters, or select the 'Variable Size' check box and specify the upper bounds in the Size box.
Any idea how i can initialise a variable/get this code working with this variable. I know that I'm running the loop for 60 iterations and I'm storing 60 values and need to output the final value. I have attached a picture by what I mean. ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/883035/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/883035/image.png)
3 commentaires
Benjamin Thompson
le 3 Fév 2022
You do not need to size variables to match the time duration of a simulation. Your S-Function just needs to update the value of all outputs to Simulink at each iteration. Then, connect the output to a "To Workspace" block or use signal logging if you want to save the past values.
Réponses (0)
Voir également
Catégories
En savoir plus sur General Applications 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!