Append vectors from different excel sheets into one vector

1 回表示 (過去 30 日間)
Agnivo Gosai
Agnivo Gosai 2019 年 3 月 12 日
編集済み: Adam Danz 2019 年 3 月 12 日
Hello, I have n excel sheets in one book, which I want to read. Each sheet has one vector, all of same length. I want to append all these vectors together in a new sheet. Could anyone tell how to do it ?

採用された回答

Adam Danz
Adam Danz 2019 年 3 月 12 日
編集済み: Adam Danz 2019 年 3 月 12 日
  1. List the file names (and full paths, if possible) to all excel sheets in a cell array.
  2. Create a loop that will loop through each excel sheet.
  3. Use xlsread() to read in each sheet within the loop and store the vector values.
  4. After the loop, put the values together into 1 long vector.
  5. Use xlswrite() to write the data into a new sheet.
Here's a template. After you read through the options in xlsread() and xlswrite() (see the links I provided), you can adapt the template to your needs.
% 1) list file names
excelFiles = {'C:\Users\vasillevski\Documents\MATLAB\sheet1.xlsx',
'C:\Users\vasillevski\Documents\MATLAB\sheet2.xlsx',
'C:\Users\vasillevski\Documents\MATLAB\sheet3.xlsx',
'C:\Users\vasillevski\Documents\MATLAB\sheet4.xlsx'};
% 2) loop through files
vectorData = cell(length(excelFiles, 1));
for i = 1:length(excelFiles)
% 3) read data
vectorData{i} = xlsread(excelFiles{i}); %adapt as needed, see documentation
end
% 4) combine values
vec = cell2mat(vectorData);
% 5) Write data to new excel file
newFileName = 'C:\Users\vasillevski\Documents\MATLAB\ALL_DATA.xlsx',
xlswrite(newFileName,vec) %adapt as needed, see documentation
Not tested.

その他の回答 (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