我的Matlab代码出错?

时间:2017-02-26 10:29:54

标签: matlab

我想对拉曼光谱进行一些计算,我有一个问题就是读取我的输入文件。我的文件.txt包含2列:X = Wavelength(cm-1)和Y = Raman intensity。文件名包含位置坐标或收集的拉曼光谱,例如(0.00,-05.00)(-2.00,-0.50)

function Read_Raman_Files
% Reads Raman spectra from txt files.
% Each file contains the data for a single Raman spectrum:
%  X = Wavelength (cm-1)
%  Y = Raman intensity
% The name of the input file contains the coordinates at which the spectrum is taken.
% Results are stored in 'data.mat'.

files = dir('-5.0,0.00.txt');
Ncurves = length(files);
if Ncurves==0, display('No txt files found!'); return; end
for i = 1:Ncurves,
    i
    fname = files(i).name;
    data = importdata(fname);
    if i==1, X = data(:,i); end
    Y(:,i) = data(:,2);
    dash = strfind(fname,'__');
    Xpos(i) = str2num(fname(strfind(fname,'Xµm_')+4:dash(2)-1));
    Ypos(i) = str2num(fname(strfind(fname,'Yµm_')+4:dash(3)-1));
end;
save('data.mat', 'Ncurves', 'X', 'Y', 'Xpos', 'Ypos');
return

1 个答案:

答案 0 :(得分:1)

以下是有关如何读取由逗号分隔的2列整数的文件内容的示例:

formatSpec = '%d%d';
[x, y] = textread('yourFile.txt', formatSpec, 'delimiter',',');