2017-02-26 86 views
0

我想對我的拉曼光譜進行一些計算,我有一個問題來閱讀我的輸入文件。我的文件.txt包含2列:X = Wavelength(cm-1)和Y = Raman intensity。文件名包含位置的座標或收集拉曼光譜,例如(0.00,-05.00)(-2.00,-0.50)我的Matlab代碼錯誤?

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 
+0

代碼包含serival了Syntex錯誤。你會告訴我你想在X和Y上執行什麼樣的計算,那麼我會根據那個修改你的代碼? –

+2

錯誤是...什麼? – excaza

+0

非常感謝您的回覆,我使用開源matlab代碼來擬合我的光譜並繪製地圖,我無法在此論壇中發佈此代碼的鏈接,但您可以在Google(搜索Amir Zabet拉曼matlab,第一鏈接) – Ben

回答

1

這裏是如何讀取具有由逗號分隔的整數的2列的文件的內容的一個例子:

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

感謝您的回放,我想插入帶有數據的txt文件。 索引超出矩陣尺寸 Read_Raman_Files(第17行)中的錯誤 \t Y(:,i)= data(:,2); – Ben

+0

dir列出當前文件夾中的文件和文件夾如果要讀取txt文件的內容,使用textscan,textread或csvread。檢查更新的響應。 –

+0

謝謝,我會盡力做到這一點 – Ben