Hello John,
To ensure that the value 'y' is output at each step of the while loop, you'll need to modify the function to store the intermediate results in an array. This way, you can capture the state of 'y' at each iteration. Here’s how you can adjust your code:
- Allocate an array to store y for each iteration.
- Save the value of y at each iteration in the array.
- Return the array containing all intermediate values.
function [y, i] = fcn_06(u)
%#codegen
coder.extrinsic('tic', 'pause')
% Init
AC_Variables = struct('AC_position', double(zeros(3, 1)));
i = 1;
max_iterations = 200000;
% Preallocate y to store results for each iteration
y = zeros(3, max_iterations);
% If AC Mode = 1 Then Initialise and Launch
AC_Variables.AC_position = u;
% Loop
while (i <= max_iterations)
[z] = calculation_06(AC_Variables);
AC_Variables = z;
% Store the current position in y
y(:, i) = AC_Variables.AC_position;
i = i + 1;
% pause(1) % Uncomment if you want to slow down the loop for debugging
end
% Trim y to only include the filled values
y = y(:, 1:i-1);
end
function [z] = calculation_06(AC_Variables)
%#codegen
AC_Variables.AC_position = AC_Variables.AC_position + 10;
z = AC_Variables;
end
Hope it helps!