MATLAB: Save workspace with same load file name

MATLABsave

How to save matlab workspace automatically with same load file name? Thank you

Best Answer

You can use code like this in a loop.
file_name_including_dot_txt='example.txt';
data=function_that_reads_your_file(file_name_including_dot_txt);
[p,fn]=fileparts(file_name_including_dot_txt);
matfilename=fullfile(p,[fn '.mat']);
save(matfilename,'data')