how to import from a csv with a different file name?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Cristian Martin
am 8 Jul. 2020
Beantwortet: madhan ravi
am 9 Jul. 2020
Hi guys!
I need to import a different data's from a lot of csv. In this example is about frews.csv. Every file has a different name, and i don't want to change every time the file name.
filename = 'C:\Users\Jhon\Desktop\MATLAB\frews.csv';
delimiter = ',';
formatSpec = '%*s%f%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'ReturnOnError', false);
fclose(fileID);
frews = [dataArray{1:end-1}];
clearvars filename delimiter formatSpec fileID dataArray ans;
% thanks for your help.
0 Kommentare
Akzeptierte Antwort
madhan ravi
am 9 Jul. 2020
https://www.mathworks.com/help/matlab/import_export/process-a-sequence-of-files.html See the last example to read multiple files with different names using dir()
0 Kommentare
Weitere Antworten (1)
Kanupriya Singh
am 8 Jul. 2020
You could store all the different filenames in an array and then use a for loop to iterate over this array, choosing one filename at a time, and execute your code inside the loop.
filenames = ['example1.csv' 'example2.csv' 'example3.csv'];
for idx = 1:length(filenames)
delimiter = ',';
formatSpec = '%*s%f%[^\n\r]';
fileID = fopen(filenames(i),'r');
%...
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu File Operations 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!