How can i loop through certain columns in matrix, for example, 3th, 5th, 6th and 7th column?

for i = 3 : [5 6 7]
M = fitlm(trening(:,[2 4 i]),trening(:,1),'linear');
e3(i) = M.SSE;
end
e3 = e3(3 : [5 6 7]);
e3 = min(e3);

Answers (1)

Try using
for k = [3 5 6 7]
M = fitlm(trening(:,[2 4 k]),trening(:,1),'linear');
e3(k) = M.SSE;
end
Though be aware that you will be updating the same columns (3,5,6,7) in e3 when you may be wanting to update the first four columns.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

NjZ
on 22 Nov 2018

Commented:

NjZ
on 22 Nov 2018

Community Treasure Hunt

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

Start Hunting!