How can I break down my for loop in faster easier steps?
Show older comments
Here's the problem, I want to extract data from an anovan table to make a new matrix with only F's value(X1, X2, X1X2) and p-value(X1, X2, X1X2). So I created a for loop. The thing is it will create a 82000x6 matrix and MATLAB crashes everytime I run it. Is there a way to separate my loop to process only 800/82000 at a time (it crashes at 900)? Here's what I have at the moment :
n=81924;
c=0;
FX1=cell(1,81924);
FX2=cell(1,81924);
FX1X2=cell(1,81924);
PValueX1=cell(1,81924);
PValueX2=cell(1,81924);
PValueX1X2=cell(1,81924);
set(0,'DefaultFigureVisible','off')
for k=1:n;
c=c+1;
[p, table, stats]=anovan((vertcat(Y(:,c),Z(:,c))),{temps, amelioration}, 'interaction');
tx1=table(2,6); %pour les F
ux1=cell2mat(tx1);
FX1{k}=(ux1);
tx2=table(3,6);
ux2=cell2mat(tx2);
FX2{k}=ux2;
tx1x2=table(4,6);
ux1x2=cell2mat(tx1x2);
FX1X2{k}=ux1x2;
px1=table(2,7); %pour les p-value
modpx1=cell2mat(px1);
PValueX1{k}=modpx1;
px2=table(3,7);
modpx2=cell2mat(px2);
PValueX2{k}=modpx2;
px1x2=table(4,7);
modpx1x2=cell2mat(px1x2);
PValueX1X2{k}=modpx1x2;
end
TOUS=horzcat(FX1.',FX2.',FX1X2.',PValueX1.',PValueX2.',PValueX1X2.');
2 Comments
the cyclist
on 16 Jun 2017
Not answering your question, but just a little side note that instead of
FX1=cell(1,81924);
FX2=cell(1,81924);
FX1X2=cell(1,81924);
PValueX1=cell(1,81924);
PValueX2=cell(1,81924);
PValueX1X2=cell(1,81924);
[FX1,FX2,FX1X2,PValueX1,PValueX2,PValueX1X2] = deal(cell(1,81924));
to accomplish the same thing.
Genevieve Nuckle
on 16 Jun 2017
Answers (1)
Steven Lord
on 16 Jun 2017
0 votes
By "crash" do you mean MATLAB shuts down (potentially with a dialog box that says something like "MATLAB needs to shut down") or do you mean you receive an error?
If MATLAB shuts down, it should have generated a crash log file. Please send that to Technical Support for further investigation using either the crash reporter dialog that should have opened when MATLAB crashed or the Contact Us link in the upper-right corner of this page.
If MATLAB throws an error, please post the full text (everything in red) of the error message you receive and we may be able to explain why you receive that error and how to eliminate it.
1 Comment
Genevieve Nuckle
on 21 Jun 2017
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!