%% Perform Pointer Arithmetic on Structure Array
% This example shows how to use pointer arithmetic to access elements of a structure. The example creates a MATLAB structure, based on the c_struct definition in the shrlibsample.h header file.
% Load the definition.

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

%
% Create the MATLAB structure.

s = struct('p1',{1,2,3},'p2',{1.1,2.2,3.3},'p3',{0});

%
% Create a pointer to the structure.

sptr = libpointer('c_struct',s);

%
% Read the values of the first element.

v1 = sptr.Value

%
% Read the values of the next element by incrementing the pointer.

sptr = sptr + 1;
v2 = sptr.Value

%
% Copyright 2015 The MathWorks, Inc.