Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Why reading in csv files will not work for me.
1 回表示 (過去 30 日間)
古いコメントを表示
I currently have approximately 16 csv files in my directory, and using matlab I want to read them all in. I have used the following code:
for files = dir('*.csv')
Q = length(files);
for n=1:Q
% Read in CSV
data = csvread(files(n).name); % Read in the data
filename = files(n).name; % Get the file name
filename; % Print the file name
end
end
When I run this script it isn't reading in any files or printing them out. Does anyone know why?
0 件のコメント
回答 (1 件)
Rik
2019 年 3 月 11 日
Why aren't you trying something like this?
files = dir('*.csv')
Q = numel(files);
data=cell(Q,1);
for n=1:Q
% Read in CSV
filename = files(n).name; % Get the file name
data{n} = csvread(filename); % Read in the data
fprintf('%s\n',filename); % Print the file name
end
And if this fails for some reason, report the error that is shown, or the size of the files variable.
2 件のコメント
Rik
2019 年 3 月 11 日
編集済み: Rik
2019 年 3 月 11 日
Than your script must have the same name as the only csv file in your current folder. Put a breakpoint next to the first line and go through this code step by step to see what happens to your variables.
You may want to put this at the top of your code:
clc,clear variables;%for debugging only
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!