Output looped values to the same array/matrix

1 次查看(过去 30 天)
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!

采纳的回答

Guillaume
Guillaume 2014-12-9
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by