フィルターのクリア

How to import csv files in MATLAB?

12 ビュー (過去 30 日間)
Abraham Caceres
Abraham Caceres 2021 年 11 月 16 日
コメント済み: Cris LaPierre 2021 年 11 月 18 日
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 件)

カテゴリ

Help Center および File ExchangeDatabase Toolbox についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by