简体   繁体   中英

Error in my Matlab code?

I would like to make some calculation on my Raman spectra, I have a problem to read my input file. My file .txt contain 2 columns: X = Wavelength (cm-1) and Y = Raman intensity . The name of the file contains the coordinates of the position or the Raman spectrum was collected, for example (0.00,-05.00) or (-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

Here is an example on how to read the content of a file that has 2 columns of integers separated by comma:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM