How to open csv file?

380 ビュー (過去 30 日間)
Noah Kilps
Noah Kilps 2020 年 9 月 16 日
コメント済み: Sebastian Thuné 2020 年 9 月 16 日
I am needing to loop through a whole folder of files, but I am struggling to figure out how to read/open the csv files once I have gotten this far:
% This counts the number of files that will need to be looped through, so
% pick the folder with all of the data desired to be run
source_dir = uigetdir([]);
d = dir([source_dir, '\*.csv']);
z = length(d);
%Get information about what's inside your folder.
myfiles = dir(source_dir);
%Get the filenames and folders of all files and folders inside the folder
%of your choice.
filenames = {myfiles(:).name}';
filefolders = {myfiles(:).folder}';
%Get only those files that have a csv extension and their corresponding
%folders.
csvfiles = filenames(endsWith(filenames,'.csv'));
csvfolders = filefolders(endsWith(filenames,'.csv'));
%Make a cell array of strings containing the full file locations of the
%files.
files = fullfile(csvfolders,csvfiles);
Filenames = string(filenames);
Filefolders = string(filefolders);

採用された回答

Sebastian Thuné
Sebastian Thuné 2020 年 9 月 16 日
Hi,
Have you tried the csvread() command?
  9 件のコメント
Noah Kilps
Noah Kilps 2020 年 9 月 16 日
I figured it out. For some reason whether the csv was all caps or lower case mattered.
Sebastian Thuné
Sebastian Thuné 2020 年 9 月 16 日
Good job! Then You can mark this as answered!

サインインしてコメントする。

その他の回答 (1 件)

Cris LaPierre
Cris LaPierre 2020 年 9 月 16 日
There are many ways to import a csv file, including
What is best depends on the contents of your files.

カテゴリ

Help Center および File ExchangeStandard File Formats についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by