How to load multiple excel files using a loop into MATLAB

Hi,
I have 58 excel files ( S (i).xlsx) and i want to load them all into MATLAB then store them in to two different cells (odd in one and even in another) I can do it one by one but it takes heaps of time. Can you please help me about this?
for i = 1:2:57;
j = 0:2:58;
x_data1 = sprintf('S (%d).xlsx',i);
x_cal = xlsread('S (i).xlsx',y);
x_data2 = sprintf('S (%d).xlsx',j);
x_cal = xlsread(x_data2);
end
PS: I'm a beginner in MATLAB.
Thanks,

 채택된 답변

Walter Roberson
Walter Roberson 2017년 6월 18일
for i = 1 : 58
filename = sprintf('S (%d).xlsx',i);
data = xlsread(filename);
if mod(i, 2) == 1
x_cal_odd{ (i + 1) / 2 } = data;
else
x_call_even{i / 2 } = data;
end
end

댓글 수: 2

Thanks Walter, it your code is working perfectly.
now I have 2 cells with size of 1x29, how can I add all of the 29 columns in one cell together and make a nx156 data file? ( the size of each is 720x156 , so I guess it will be 13680x156) I want to give this to neural network.
BigMatrix{1} = cell2mat( FirstCell(:) );
BigMatrix{2} = cell2mat( SecondCell(:) );
Note: 29 by 720 is 20880 not 13680: 13680 would be what you would get for 19 by 720

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by