MATLAB: How do you plot sequentially numbered files on one plot

delimited filesgraphsequentially numbered

I am new to MATLAB and have created ascii folders with 30 .asc files in each that I would like to plot on one graph. I have tried to figure out how to do this, but have a limited understanding of MATLAB. I know I need to include the matrix size (200:1), but this is actually 2 columns with x,y values in it.
So far all I have is:
Files = ('sample1_1_*.asc');
clf,figure,hold on;
for k = 1:30
plot(Files(k,:))
end
But this gives an error of 'Index exceeds matrix dimensions.'
Any help would be much appreciated or if you could direct me to a relevant post that would be fantastic!

Best Answer

Assuming your asc txt files stores the data in the following pattern:
x y
x y
x y
Save the following functions as plotAscData.m, and run plotAscData
> plotAscData
function plotAscData
%Select multiple files and store the file name into a cell array
[FileName, FilePath] = uigetfile('*.asc', 'Open files', 'multiselect', 'on');
if ischar(FileName)
FileName = {FileName};
elseif isnumeric
warning('No file selected');
return;
end
figure;
hold on;
for f = 1:length(FileName)
FullFileName = [FilePath FileName{f}];
M = readAscFile(FullFileName); %Reads csv file as a matrix
x = M(:, 1); %Assuming x values are the 1st column
y = M(:, 2); %Assuming y values are the 2nd column
plot(x, y);
end
hold off;
function M = readAscFile(AscFileName)
FID = fopen(AscFileName, 'r'); %Access asc file
%Count number of columns, if possible
if feof(FID) == 0
TextLine = fgetl(FID);
NumCol = length(regexpi(TextLine, '\s', 'split'));
else %Nothing in this file
warning('File is empty.');
M = [];
return;
end
fseek(FID, 0, 'bof'); %Return to file beginning
FileStrFormat = repmat('%f', 1, NumCol); %Specify asc data format
ScannedText = textscan(FID, FileStrFormat); %Read the data into a cell array
%Convert the ScannedText cell array into the double array M
M = zeros(length(ScannedText{1}), NumCol); %Preallocate double matrix M
for j = 1:NumCol
M(:, j) = ScannedText{j};
end
fclose(FID); %Close file to free up memory