Initialise a variable which changes sizer each iteration in simulink coder
조회 수: 1 (최근 30일)
이전 댓글 표시
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
Benjamin Thompson
2022년 2월 3일
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.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 General Applications에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!