MATLAB: For loop store values

cell2matfor loopMATLABsavestore

so I am convinced there is a better way for me to approach the following code:
ftse = xlsread('ftse123.xlsx');
L = length(ftse);
s = floor(L/10);
f25 = ftse(:,3);
k=1;
h=1;
for i = 1:10
j=s*i;
h=s*(i-1);
if h== 0
h=1;
else
h=s*(i-1);
end
y{i} = f25(h:j,:);
end
x1=cell2mat(y(1));
x2=cell2mat(y(2));
x3=cell2mat(y(3));
x4=cell2mat(y(4));
x5=cell2mat(y(5));
x6=cell2mat(y(6));
x7=cell2mat(y(7));
x8=cell2mat(y(8));
x9=cell2mat(y(9));
x10=cell2mat(y(10));
I used copy and paste after struggling to save the values x1 etc, within the for loop.
Also noticed that x1 is has a length of 522 and not 523 like the rest?
The code achieves what I want/need but must be long and drawn out.
any advice would be great thanks.

Best Answer

I would recommend that you use readtable or importdata and use a table to store, group, and process your data. In lieu of that, here is some simple code to group the third column into ten groups:
>> N = size(ftse,1);
>> V = linspace(1,11,N+1);
>> V = fix(V(1:end-1));
>> C = accumarray(V(:),ftse(:,3),[],@(v){v});
It is much simpler and more efficient to access the cells of C using indexing. Do NOT create numbered variables.
"Also noticed that x1 is has a length of 522 and not 523 like the rest?"
Because ftse has 5225 rows. There is no way to split this into ten equally sized groups:
>> size(ftse)
ans =
5225 4
>> size(ftse,1)/10
ans =
522.5
Half the groups will have 252, half have 253 elements. My code spreads these evenly through C:
>> cellfun('size',C,1)
ans =
523
522
523
522
523
522
523
522
523
522