Read multiple csv and plot
8 ビュー (過去 30 日間)
古いコメントを表示
I have several csv files in a folder. I want to plot some graphes with each file.
This is my original code. It works, but I have to change file path every time.
csv_file = fopen('C:\Users\testing.csv','rt');
formatSpec = '%s%s%s%s%s%s%s%s%s%s%s';
C = textscan(csv_file, formatSpec, 'Delimiter', ';');
fclose(csv_file);
This the code that I manage to extract several files in a folder.
csv_dir = uigetdir(' ');
file_list = dir(fullfile(csv_dir, '*.csv'));
file_list_num = size(file_list);
file_list_names = {file_list.name};
csv_file = fopen('file_list','rt');
formatSpec = '%s%s%s%s%s%s%s%s%s%s%s';
C = textscan(csv_file, formatSpec, 'Delimiter', ';');
fclose(csv_file);
Error code:
Error using textscan
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in Untitled2
C = textscan(csv_file, formatSpec, 'Delimiter', ';');
0 件のコメント
採用された回答
dpb
2019 年 3 月 13 日
formatSpec = '%s%s%s%s%s%s%s%s%s%s%s';
csv_dir = uigetdir(' ');
d=dir(fullfile(csv_dir, '*.csv'));
for i=1:numel(file_list)
fid = fopen(fullfile(d(i).folder,d(i).name),'r');
C = textscan(csv_file, formatSpec, 'Delimiter', ';');
fid=fclose(fid);
...
DIR() returns a struct of directory info; have to dereference it...plus you have the text string 'file_list' in the argument, not the variable altho that alone wouldn't fix the problem.
See
doc dir
for full syntax, examples, etc., ...
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で File Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!