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

6 ビュー (過去 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 Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by