Copy colums from different Excel file and paste them in a single spreadsheet to obtain a matrix

3 ビュー (過去 30 日間)
Laura
Laura 2015 年 10 月 5 日
コメント済み: Laura 2015 年 10 月 13 日
Hi! I am new to MATLAB and I am working with a serie of different excel files (I have a lot of them!). For each file I want to copy just one column and then paste it in another spreadsheet so that at the end I have one single spreadsheet with a big matrix made of all the columns I have copied. I have done a part of the code that allows me to read my excel files one after another and subset the column I want but then I don't know how to "paste" them all together in one single excel file, any idea?
Source_directory='H:\dos\Master Project\Test matlab\Results';
Destination_directory='H:\dos\Master Project\Test matlab\Results\One matrix';
source_files = dir(fullfile(Source_directory, '*.xlsx'));
for m=1:length(source_files)
sheet=1;
data_total_flow = xlsread(fullfile(Source_directory, source_files(m).name),sheet,'B:B')

回答 (1 件)

ES
ES 2015 年 10 月 5 日
You can use the complementary xlswrite function to write data into excel file in the sheet you need starting at the cell you need.
  3 件のコメント
Image Analyst
Image Analyst 2015 年 10 月 5 日
Specify both the same filename and the same worksheet name and they should go onto the same sheet.
Laura
Laura 2015 年 10 月 13 日
I tried as you suggest but I could either write each output column in a separate excel file or write only the last output column (xlswrite outside the loop). I don't know how to use xlswrite to write all my output columns in one single spreadsheet in order to create a matrix.
for i=1:length(source_files)
sheet='patterns';
raw_data=xlsread(fullfile(folder_path,source_files(i).name),sheet);
raw_data(:,1)=[];%eliminate first colum
raw_data(1:11,:)=[];%eliminate headers
total_flow=sum(raw_data,2);
%xlswrite(fullfile(dest_directory, source_files(i).name),total_flow);
end
xlswrite('Matrix total flow',total_flow)

サインインしてコメントする。

カテゴリ

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