Extracting one column from multiple csv files into one with a mix of numbers and variables

조회 수: 5 (최근 30일)
Hi everyone, I am new to matlab, and would really appreciate some help. I have roughly 100 csv files with a mix of numbers and variables. All the files have the same format in term of number of columns but with variable number of rows, and I need to extract the numerical data from a specific column (E-'PathLength') from each, without the header itself, and copy the data to a new file which will contain the filename as the header and the data underneath it. I am attaching a sample file. Thank you so much!
  댓글 수: 1
oded mayseless
oded mayseless 2018년 4월 16일
here is the code I have so far...
myDir = uigetdir; %gets directory
ds = tabularTextDatastore(myDir,'FileExtensions','.csv');%get a list of all the csv files in the folder
fileNames = (ds.Files); %generate a variable with the actual file names
for k = 1:numel(fileNames)
fid = readtable(fileNames(k)); % read the file in position 'k' in the fileNames array
PathLength = fid(:,5); % read the 5th column from the csv file
write = {fileNames(k), PathLength}; % make an array of what I want to write to an excell file
xlswrite('data',write,(A,k)); %write it in an excell file in column a row(
end

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by