How to import csv files in MATLAB?

22 次查看(过去 30 天)
I'm having trouble importing an entire csv folder into matlab workspace. I created the file path for the numerous csv files but, do not know how to load them into the workspace next in order to filter and plot? Please advise.
myFolder = 'C:\Users\AbrahamCaceres\Documents\My Documents\Clean Data';
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s\nPlease specify a new folder.', myFolder);
uiwait(warndlg(errorMessage));
myFolder = uigetdir();
if myFolder == 0
return;
end
end
filePattern = fullfile(myFolder, '**/*.csv');
theFiles = dir(filePattern);
for k = 1: length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile('c:\','theFiles','matlab',baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Move files into workspace? Then filter & plot data.
end

采纳的回答

Cris LaPierre
Cris LaPierre 2021-11-16
Use readtable, readmatrix, or readcell. My preference is readtable.
  6 个评论
Abraham Caceres
Abraham Caceres 2021-11-18
I used the code recommended. Making progress but all the files are combining together into one labeled data. My goal is to load the files seperately instead of as one. I have files labeled Refined1.csv and Raw1.csv and they are being combined together instead of seperate. What I tried below didn't make a difference as well.
fullFileName = fullfile(theFiles(k).folder,theFiles(k).name,filesep)
Cris LaPierre
Cris LaPierre 2021-11-18
You need to implement some flow control based on the file name. See Ch 12 of MATLAB Onramp.

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by