# How can I take the average of certain columns in each excel sheets

조회 수: 5 (최근 30일)
Marion 2023년 7월 20일
답변: Mathieu NOE 2023년 7월 21일
I have an excel file with multiple sheets. In sheet # 1, I want to take the average of column 1 and the average of column 5, then store each result in a new file. Iwant to repeat this process to all the remaining sheets in my excel file.
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Dyuman Joshi 2023년 7월 20일
Read the excel sheet using readmatrix or readtable, use indexing to take the mean of the columns 1 and 5, and use writematrix or writetable to store the result in a new file.
If you have any more questions, show what you have attempted and ask a specific question (where you are having trouble).

댓글을 달려면 로그인하십시오.

### 답변 (1개)

Mathieu NOE 2023년 7월 21일
hello Marion
see my example below (the dummy excel file is attached)
hope it helps
% Importing Data from excel across multiple sheets.
filename = 'Classeur1.xlsx';
[~,sheet_name]=xlsfinfo(filename);
nsheets = numel(sheet_name);
% retrieve and process data
for k=1:nsheets
col1_averaged(k,:) = mean(T(:,1)); % average of column 1
col5_averaged(k,:) = mean(T(:,5)); % average of column 5
end
%% export results as table
out_table = array2table([col1_averaged col5_averaged],'VariableNames',{'col 1 averaged' 'col 5 averaged'});
writetable(out_table,'out.xlsx',"Sheet",1);

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by