www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/ShrlibPassPointerToStructureExample.m
%% Pass Pointer to Structure % This example shows how calling the |addStructByRef| function with a pointer % modifies the fields in the input argument. % Copyright 2015 The MathWorks, Inc. if not(libisloaded('shrlibsample')) addpath(fullfile(matlabroot,'extern','examples','shrlib')) loadlibrary('shrlibsample') end %% % Create a structure of type |c_struct|. S.p1 = 20; S.p2 = 99; S.p3 = 3; %% % Create a pointer |sp| to the structure. sp = libpointer('c_struct',S); sp.Value %% % Pass the pointer to the function. res = calllib('shrlibsample','addStructByRef',sp) %% % When you pass a pointer, the function modifies the fields in the structure it points to. sp.Value %% %