How to write names of txt files on top cell of each calculated column in an excel file?

1 回表示 (過去 30 日間)
Hi all,
I have a folder with several txt files in it.
My calculating code runs perfect and the final outcome is an excel file with columns of data for each file, as below:
filenameList = dir('C:\Users\myself\Desktop\test\*.txt');
finalArray = [];
for filenameIndex = 1:length(filenameList)
filename = [filenameList(filenameIndex).folder '\' filenameList(filenameIndex).name];
inData = importdata(filename,'\t',8);
inData = inData.data;
outArray = Calc1(inData);
outArray2 = Calc2(outArray);
finalArray = [finalArray outArray2];
end
filename = xlswrite('output.xlsx',finalArray);
How can I tweak it to add the file names on the top cell of each column (each column represnt the calculated data for each txt files) of the excel file?
thanks

採用された回答

Walter Roberson
Walter Roberson 2022 年 3 月 3 日
array2table with the 'variablenames' option, and writetable() instead of xlswrite
  10 件のコメント
Walter Roberson
Walter Roberson 2022 年 3 月 9 日
filename = fullnames{filenameIndex};
Aramis
Aramis 2022 年 3 月 9 日
Hey Walter, Thanks for your help. It worked great and the output looks valid.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by