Initialise a variable which changes sizer each iteration in simulink coder
1 view (last 30 days)
Show older comments
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.
3 Comments
Benjamin Thompson
on 3 Feb 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.
Answers (0)
See Also
Categories
Find more on General Applications in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!