How I can to get the name of a file.mat when i load it?
49 views (last 30 days)
Hello, i want to get the name of a file.mat when i load it. For example, I load 'Resonator.mat', how i can to get the string 'Resonator' when i load it?
I know how to load a .mat file and how to save it, but i need the get the name because i want to overwrite the variables of the .mat and save with the same name(i have a lot of .mat and i can't fix the name).
Vishwas Kumar on 9 Jan 2018
You can use something like uigetfile
fileName = uigetfile('*.mat');
filename = filename(1:end-4)
Or alternatively, you can do some batch processing doing something like:
dirinf = dir('*.mat');
nfiles = length(dirinf);
for n = 1:nfiles
infile = dirinf(n).name; % extract one file name from struct
load(infile) % load the data
infile = infile(1:end-4);