Check out example codes for "save mat file script in matlab directory". It will help you in understanding the concepts better.

Code Example 1

%get the directory of your input files:
pathname = fileparts('/input/file');
%use that when you save
matfile = fullfile(pathname, 'output.mat');
figfile = fullfile(pathname, 'output.fig');
save(matfile, ...');
saveas(figfile, ...');

Learn ReactJs, React Native from akashmittal.com