MATLAB: Can anyone please correct this code for me

for looplooploopssequence

Hi,
I am trying to extract data from a sequence of files. I also need to extract the value of x that corresponds to peak y value from each plot. I have tried the following code but I can't get results. I would be grateful if someone can check it for me. I have attached herewith the files for your kind reference.
close all; clear all; clc;
folder = cd;
for k = 1:2;
for j = 1:2;
matFilenameA = sprintf('X%d.out', k);
matData1 = load(fullfile(cd, matFilenameA));
%
matFilenameB = sprintf('Y%d.out', j);
matData2 = load(fullfile(cd, matFilenameB));
x = matFilenameA(:,2);
y = matFilenameB(:,2);
[maxvaly,idx] = max(y) ;
maxvalx = x(idx);
fid=fclose('all');
end
end

Best Answer

files = dir('*.txt') ;
N = length(files) ;
iwant = zeros(N,2) ;
for i = 1:N
data = importdata(files(i).name) ;
[val,idx] = max(data(:,2)) ;
iwant(i,:) = [data(idx,1),val] ;
end
Copy all the text file sin one folder and runt his code.