How do I import multiple text files and automatically add them into a single cell array? Maybe 3D?
이전 댓글 표시
Hey everyone, I'm trying to streamline some mass spec data I want to prepocess before uploading to a statistical software package. I exported my data as ASCII to just get the x and y coordinates and where each spectra is saved in seperate file. I have saved all these files I want to process into one folder.
Below is the script I used so far in order to import the data to matlab and it's not the greatest.
%This code extracts the data from the folder
%written for ".txt" files below
files=dir('*.txt');
names_cell={files.name}
%Extract the Y axis for each spectra in out all of them into a single array
for i=1:length(names_cell)
Y(:,i)=dlmread(names_cell{i},' ',0,1);
end
%Extract the X axis from the first data file (assuming they are all te same
for i=1
MZ=dlmread(names_cell{1},' ',0,0)
MZ(:,2)=[]
end
This has avenue hasn't been fruitful since many Matlab Answers recommends to avoid dynamic variable naming and down the line, this method has made things more confusing when writing script. My biggest concern is the script I created above above assumes that the x axis (m/z) is uniform for each data file (I might input data from different instruments soon). Also maintaining the filename would be great so I know what spectra goes with what sample.
Is there way to generate a cell array that contains the filename, the x axis, and the y axis? Would making a 3D array help becuase that has gotten me out of pickles before, but not sure how to do it with importing data.
Thanks for any help!! Going through the school of hard knocks to learn Matlab.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!