function [size_regular, size_online] = mpcmemorysize(data)
% Compute data memory usage of an MPC Controller in single precision in K
% bytes. The second output is the memory size when online tuning is
% enabled.  Input "data" is a @mpcdata object with IsDirty = false.

% Author(s): Rong Chen
% Copyright 2013 The MathWorks, Inc. 

%% Define MPC data matrices
regular_matrices = {'Hinv';'Linv';'Ac';'Kx';'Ku1';'Kut';'Kr';'Kv';'Mx';'Mu1';'Mv'};
online_matrices = {'Wy';'Wdu';'Wu';'Jm';'SuJm';'Su1';'Sx';'Hv';'I1'};
%% Return size estimation in kB for single precision
size_regular = 0;
for ct=1:length(regular_matrices)
    size_regular = size_regular + numel(data.(regular_matrices{ct}));
end
size_regular = size_regular + 8*numel(data.H);
size_online = 0;
for ct=1:length(online_matrices)
    size_online = size_online + numel(data.(online_matrices{ct}));
end
size_regular = ceil(size_regular*4/10000)*10;
size_online = ceil(size_online*4/10000)*10;
