0

By an old post (https://stackoverflow.com/a/13744310/3900582) I have been able to read all the .csv-files in my folder into a cell array. Each .csv-file has the following structure:

0,1024
1,427
2,313
3,492
4,871
5,1376
6,1896
7,2408
8,2851
9,3191

Where the left column is the x-value and the right column is the y-value.

In total, there are almost 200 files and they are each up to 100 000 lines long. I would like to plot the contents of the files in one figure, to allow the data to be more closely inspected.

Community
  • 1
  • 1
GLaDER
  • 345
  • 2
  • 17

1 Answers1

0

I was able to use the following code to solve my problem:

dd = dir('*.csv');

fileNames = {dd.name}; 

data = cell(numel(fileNames),2);
data(:,1) = regexprep(fileNames, '.csv','');

for i = 1:numel(fileNames)    
   data{i,2} = dlmread(fileNames{i});
end

fig=figure();
hold on;

for j = 1:numel(fileNames)

    XY = data{j,2};
    X = XY(:,1);
    Y = XY(:,2);

    plot(X,Y);

end
GLaDER
  • 345
  • 2
  • 17