%% Preconvert MATLAB Structure Before Adding Values
% This example shows how to preconvert structure sm to c_struct before calling  addStructFields. If you repeatedly pass sm to functions, preconverting eliminates the processing time required by MATLAB to autoconvert the structure for each function call.
% Create and initialize a MATLAB structure.

sm.p1 = 476;
sm.p2 = -299;
sm.p3 = 1000;

%
% Load the library containing the addStructFields function.

if not(libisloaded('shrlibsample'))
    addpath(fullfile(matlabroot,'extern','examples','shrlib'))
    loadlibrary('shrlibsample')
end

%
% Convert the fields, which are of type double, to match the c_struct structure types, double, short, and long.

sc = libstruct('c_struct',sm);

%
% Display the field names and values.

get(sc)

%
% Add the field values.

calllib('shrlibsample','addStructFields',sc)

% Copyright 2015 The MathWorks, Inc.