MATLAB: Saving a file with name of reference of other file name

filenameloadmatstl

Hello all; I want to save two types of file(.stl and .mat) in which one file (.stl) will be saved by user with particular name . I need '.mat' type of file to be saved with having reference of title of '.stl' type file so that I can load .mat file automatically . for example – "abc.stl" and "abc_1.mat" ; "head.stl" and "head1.mat" here I am using .stl file for generating volume data (for saving faces and vertices) and .mat file for saving variables . Thankyou

Best Answer

When Filename is the user-provided filename (such as by way of uiputfile() ), then
mat_suffix = '_1.mat';
[filedir, basename, ext] = fileparts(Filename);
matFilename = fullfile(filedir, [basename mat_suffix]);