MATLAB: How to read and save different variables in a matfile to another mat file

MATLAB

How to read two specific variables from a .mat file having different variables and save it to another .mat file without changing the variable name.

Best Answer

S = load('file1.mat','var1','var2');
save('file2.mat','-struct','S')
OR
S = load('file1.mat');
save('file2.mat','-struct','S','var1','var2')