フィルターのクリア

Run code through multiple excel files

1 回表示 (過去 30 日間)
krysten spencer
krysten spencer 2018 年 2 月 18 日
編集済み: krysten spencer 2018 年 2 月 19 日
I have this code I have written to access a single excel file and go through specific columns and then count the number of non zero elements in that column, the code then prints each columns total in a new excel sheet. What I am trying to do is have this code run through multiple excel sheets doing the same thing but print out one output file - with each new row being the next participants results. Any help would be appreciated!
if true
% code
numData = xlsread('p_2.xlsx');
participantNumber = numData(2,1);
buttonAmount = numData(:,3);
Ar = nnz(buttonAmount);
buttonAmount2 = numData(:,4);
Br = nnz(buttonAmount2);
buttonAmount3 = numData(:,5);
Xr = nnz(buttonAmount3);
buttonAmount4 = numData(:,6);
Yr = nnz(buttonAmount4);
buttonAmount5 = numData(:,7);
RRr = nnz(buttonAmount5);
buttonAmount6 = numData(:,8);
ZRr = nnz(buttonAmount6);
buttonAmount7 = numData(:,9);
SBr = nnz(buttonAmount7);
buttonAmount8 = numData(:,10);
SLr = nnz(buttonAmount8);
buttonAmount9 = numData(:,11);
SRr = nnz(buttonAmount9);
buttonAmount10 = numData(:,12);
SXr = nnz(buttonAmount10);
sumPresses = Ar+Br+Xr+Yr+RRr+ZRr+SBr+SLr+SRr+SXr
T=table(participantNumber,Ar,Br,Xr,Yr,RRr,ZRr,SBr,SLr,SRr,SXr,sumPresses);
fileName='buttonpresses.xls';
writetable (T,fileName);
end

採用された回答

Are Mjaavatten
Are Mjaavatten 2018 年 2 月 19 日
編集済み: Are Mjaavatten 2018 年 2 月 19 日
You could try something like this:
Names = {'participantNumber';'Ar';'Br';'Xr';'Yr';'RRr';'ZRr';'SBr';...
'SLr';'SRr';'SXr';'sumPresses'};
fileName='buttonpresses.xls';
xlswrite(fileName,Names,'Sheet1','A2');
infiles = {'p_2.xlsx','p_3.xlsx','p_4.xlsx'};
for i = 1:length(infiles)
numData = xlsread(infiles{i});
cellname = [char(65+i),'1'];
xlswrite(fileName,infiles(i),'Sheet1',cellname);
<your stuff>
X = [participantNumber,Ar,Br,Xr,Yr,RRr,ZRr,SBr,SLr,SRr,SXr,sumPresses]';
cellname = [char(65+i),'2'];
xlswrite(fileName,X,'Sheet1',cellname);
end
  4 件のコメント
Walter Roberson
Walter Roberson 2018 年 2 月 19 日
char(65+i) is going to fail after 25 files. You can grab something from the File Exchange such as https://www.mathworks.com/matlabcentral/fileexchange/28343-column-converter-for-excel
krysten spencer
krysten spencer 2018 年 2 月 19 日
編集済み: krysten spencer 2018 年 2 月 19 日
I am just learning how to use matlab and I am not sure how to use this- do you have any examples? Thank you so much for the assistance.

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

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