How I can to get the name of a file.mat when i load it?
22 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Abel Romero
am 4 Jan. 2018
Kommentiert: Steven Lord
am 22 Okt. 2022
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).
0 Kommentare
Akzeptierte Antwort
Vishwas Kumar
am 9 Jan. 2018
fileName = uigetfile('*.mat');
load(fileName)
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);
end
2 Kommentare
ELLER JUCO
am 22 Okt. 2022
how do you find the size from the fileName?
m=size(fileName) - does not work
Steven Lord
am 22 Okt. 2022
Find the size of what from the file name?
The size of the file on disk? Use dir.
locationOfCensusMat = which('census.mat')
D = dir(locationOfCensusMat)
The sizes of the variables in the file? Use whos.
W = whos('-file', locationOfCensusMat)
W(1)
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Whos finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!