I've had a few problems with MATLAB resetting the library path. As a fix, I've appending the following to all AFNI commands before calling them via MATLAB. Hope this helps!
export DYLD_LIBRARY_PATH=""
So for example a command to do quick masking of a dataset via 3dcalc looks like this:
mask_command = ['export DYLD_LIBRARY_PATH=""; 3dcalc -a ',...
reg_outputfile, '.TMP+tlrc -b mask.nii.gz ',...
'-expr ''step(b)*a'' -prefix ', reg_outputfile];
system(mask_command);