MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。

0

Why reading in csv files will not work for me.

Claire McEldowney さんによって質問されました 2019 年 3 月 11 日
最新アクティビティ Rik
さんによって 編集されました 2019 年 3 月 11 日
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 件のコメント

サインイン to comment.

タグ

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 件のコメント

I Have run the script and in the command window it just shows the script name, rather than the names of the csv files?
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

サインイン to comment.



Translated by