Importing multiple text files into MATLAB
Mostra commenti meno recenti
I am trying to import multiple text files into MATLAB and save it as a .mat file after it has been imported. It works when I do it one file at a time by using the following command, for example:
T1_1041 = importdata('20101011_114543_VIN9375_Trigger01.txt');
but when I try to save the file name into a variable and try to use the importdata function with that variable as the file name. It does not work, like below:
myfile = '20101011_114543_VIN9375_Trigger01.txt'
[files,path] = uigetfile('MultiSelect', 'on');
for n=1:length(files);
myfile = files(n);
files(n).data=importdata(myfile);
save files(n).data
end
It gives an error inside the importdata function.
1 Commento
Jan
il 7 Feb 2011
Please use the code formatting to improve the readability. If you get an error, it would be very helpful to post the error message.
Risposta accettata
Più risposte (1)
Doug Eastman
il 7 Feb 2011
To be more robust to directory changes or single file selections, you might want to use something like the following:
[files,path] = uigetfile('MultiSelect', 'on');
if iscell(files)
for n = 1:length(files)
data = importdata(fullfile(path,files{n})); % fullfile including path
% save data
end
else
data = importdata(fullfile(path,files));
% save data
end
Categorie
Scopri di più su Text Files in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!