How can i use a loop for various sheet in excel?

3 次查看(过去 30 天)
Hello everybody, i am new in matlab, and i have a very simple question...
i have eight sheets with datas and i wan to applied the mean and the sort for everyone in the column, and yes this programm do that, but i have to copy and paste for every document, for example this is for Temperature in eight years, but i want to continous with humidity, velocity of wind and other variables.
So if you can help me ,I would really appreciate it
this is my code:
HE1=xlsread('HEN','1');
k=1:8
for k=1:1
HE1=xlsread('HEN',1);
p=mean(HE1);
ps=sort(p);
xlswrite('datosexcel4.xlsx', ps, 'Hoja1', 'A1');
HE2=xlsread('HEN',2);
p=mean(HE2);
ps=sort(p);
xlswrite('datosexcel4.xlsx', ps, 'Hoja1', 'A2');
HE3=xlsread('HEN',3);
p=mean(HE3);
ps=sort(p);
xlswrite('datosexcel4.xlsx', ps, 'Hoja1', 'A3');
HE4=xlsread('HEN',4);
p=mean(HE4);
ps=sort(p);
xlswrite('datosexcel4.xlsx', ps, 'Hoja1', 'A4');
HE5=xlsread('HEN',5);
p=mean(HE5);
ps=sort(p);
xlswrite('datosexcel4.xlsx', ps, 'Hoja1', 'A5');
HE6=xlsread('HEN',6);
p=mean(HE6);
ps=sort(p);
xlswrite('datosexcel4.xlsx', ps, 'Hoja1', 'A6');
HE7=xlsread('HEN',7);
p=mean(HE7);
ps=sort(p);
xlswrite('datosexcel4.xlsx', ps, 'Hoja1', 'A7');
HE8=xlsread('HEN',8);
p=mean(HE8);
ps=sort(p);
xlswrite('datosexcel4.xlsx', ps, 'Hoja1', 'A8');
end

采纳的回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2020-1-9
编辑:KALYAN ACHARJYA 2020-1-9
Excel_files=dir('C:\Work\steven_work\*.xlsx');
for i=1:length(Excel_files)
fName=strcat('C:\Work\steven_work\',Excel_files(i).name); % Excels Files Folder Path
data1=xlsread(fName,i);
[~,filename,~]=fileparts(fName);
xlswrite([filename,'.xlsx'],data1,'Sheet');
end
#Do minor mdification. as required. I hope you get the idea (Do Search other FAQ to call files, another option to use fullfile)
  2 个评论
Ana Soph
Ana Soph 2020-1-9
Thanks,
but I have problems applying it to my program
Ana Soph
Ana Soph 2020-1-9
i finally got it !
clear; clc
for i=1:8
TE = xlsread('TEN',i);
p = mean(TE);
ps = sort(p);
A(i,:)= ps;
end
xlswrite('datosexcelprueba.xlsx', A, 'Hoja1','A1');

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by