MATLAB: Combine NchooseK with FitLM and FOR cycle

#nchoosekfitlmfor loopMATLAB

I've got a matrix A containing 1000 x 9 data " Predictor Variables", and a Y matrix containing 1000×1 data " Response Variable". I need to launch automatically lots of FitLM commands but with only 3 data of A matrix each time (not 9 all together). The combination of 3 data from 9 from A matrix are 84 that I can obtain with NchooseK:
v = [1 2 3 4 5 6 7 8 9];
p = nchoosek(v,3)
about FitLM the command is this but I need to use only 3 column/data from A predictor and not 9 as the following code.
mdl = fitlm(A,Y)
How can combine NchooseK data with FitLM with a FOR loop or something else??? I need to bring and put each time a different combination of 3 data from row of NchooseK and put it in FitLM, but I don't know how do that.
Thanks for help.

Best Answer

v = [1 2 3 4 5 6 7 8 9];
p = nchoosek(v,3);
Nr = size(p,1);
mdl = cell(Nr, 1);
for K = 1 : Nr
these_cols = p(K,:);
thisA = A(:,these_cols);
mdl{K} = fitlm(thisA, Y);
end
Or you could do this more compactly with
v = [1 2 3 4 5 6 7 8 9];
p = nchoosek(v,3);
Nr = size(p,1);
mdl = cell(Nr, 1);
for K = 1 : Nr
mdl{K} = fitlm( A(:,p(K,:)), Y);
end
The fitted models are mdl{1}, mdl{2}, mdl{3}, ...