如何将特定的.csv文件信息放在特定的矩阵位置?

时间:2014-05-13 15:00:00

标签: matlab file pixel text-processing

我有许多文件(例如100张),其中包含CCD相机的512x512像素的强度,每个文件的光频率不同。 这些文件的格式如下:

1, 1, 602
1, 2, 598
1, 3, 546

第一个数字是像素的行,第二个是像素的列,最后一个是像素的强度。

我希望每个像素都有一个数组。到目前为止,这是我的代码:

%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);  

在这部分之后,我不太确定如何继续。我希望Pixel(1,1,:)是我第一个像素的所有强度,这些信息来自每个文件。

马克 - 奥利弗

1 个答案:

答案 0 :(得分:1)

试试这个 -

%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