Try this -
%the user selects the "many files"%
filenames = uigetfile('*.csv','','','Multiselect','on');
%here to know the number of different frequency for each pixel
NumFiles = numel(filenames);
%There are 512x512 pixels, each with NumFiles different intensities
Pixel = cell(512,512,NumFiles)
count = 0
num_pixels = size(Pixel,1)*size(Pixel,2)
for k = 1:NumFiles
fid = fopen(char(filenames(k)));
C = textscan(fid, '%d, %d, %d')
Pixel(count + sub2ind(size(Pixel),C{1},C{2})) = num2cell(C{3});
count = count + num_pixels;
fclose(fid);
end