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,

 Réponse acceptée

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 commentaires

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by