Output looped values to the same array/matrix

1 view (last 30 days)
Basically, I have the code below. I want to generate 2 output files, one for B and one for PVAL, each of which should contain the outputs for each loop so I am left with 1 sheet containing all of the B values for each loop, and another sheet containing all of the PVAL values for each loop.
What do I need to add to the code to achieve this?
for i = 1:size(data,1)/8
xx=data(8*i-7:8*i,2:3); yy=data(8*i-7:8*i,1);
[B,SE,PVAL,INMODEL,STATS,NEXTSTEP,HISTORY]=stepwisefit(xx,yy,'penter',.05);
end
Thanks in advance for any help!

Accepted Answer

Guillaume
Guillaume on 9 Dec 2014
You just need to predeclare your B and PVAL with the appropriate size and use your i index to put the result of stepwisefit in the relevant column:
numsteps = size(data, 1)/8;
B = zeros(2, numsteps);
PVAL = zeros(2, numsteps);
for i = 1:numsteps
xx=data(8*i-7:8*i,2:3); yy=data(8*i-7:8*i,1);
[B(:, i), ~, PVAL(:, i)] = stepwisefit(xx, yy, 'penter', .05)
end

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!