How can I import multiple .CSV files in MATLAB with no sequential filename?

90 vues (au cours des 30 derniers jours)
Farhan K
Farhan K le 24 Fév 2020
Modifié(e) : Stephen23 le 28 Fév 2022
I need to import 175 “.csv” files where each file contains 100 measurements from 400 items (Columns and Rows respectively). I have to write a script to import the data. The .csv files are named as D059546, D067966, D077936 etc.
Please HELP!
  3 commentaires
Farhan K
Farhan K le 24 Fév 2020
Thanks a lot. But before writing the script using dir method, it mentions to use function syntax to pass the name of the file to the import or export function. How to do that? Also how can I mention the file address folder?
Stephen23
Stephen23 le 24 Fév 2020
Modifié(e) : Stephen23 le 25 Fév 2020
"...it mentions to use function syntax to pass the name of the file to the import or export function. How to do that?"
The examples on that page use function syntax, so just follow those examples. If you want to know more:
"Also how can I mention the file address folder?"
Use fullfile to create an absolute/relative filename:

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 24 Fév 2020
Modifié(e) : Stephen23 le 25 Fév 2020
P = 'relative/absolute path to the folder where the files are saved';
S = dir(fullfile(P,'*.csv'));
for k = 1:numel(S)
F = fullfile(P,S(k).name);
S(k).data = csvread(F);
end
  5 commentaires
Sara Nasir
Sara Nasir le 28 Fév 2022
How should I skip the first line when attaempting to read the file by csvread command?
I know that fopen can be used but its giving that identifier error.
Stephen23
Stephen23 le 28 Fév 2022
Modifié(e) : Stephen23 le 28 Fév 2022
"How should I skip the first line when attaempting to read the file by csvread command?"
Specify the row option: csvread(filename,1,0)
"I know that fopen can be used but its giving that identifier error."
CSVREAD does not use FOPEN.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by