64 views (last 30 days)

c=19;

>> D=[];

>> for k=1:c;

Z=[X(:,1),Y(:,1)];

p=anova1(Z)

D=save(p)

X(:,1)=[];Y(:,1)=[];

end

James Kristoff
on 13 May 2013

% X and Y are 3x19 matricies

%

% This syntax makes sure that if you end up having more (or less) columns

% in the future, you don't need to change the code

numColumns = size(X, 2);

% Pre-allocate for speed (create a 1 x numColumns vector)

p = zeros(1, numColumns);

% I used length(p) here to signal the intent that the loop is meant for

% modifying the vector p

for k = 1:length(p);

% using the loop variable *k* means that MATLAB will use a different

% column from X and Y to create Z for each loop

Z=[X(:,k),Y(:,k)];

% this will store the resulting value in the k-th position in the vector

% *p*

p(k)=anova1(Z);

end

bym
on 9 May 2013

c=19;

% D=[];

p = zeros(c,1); % preallocate

for k=1:c;

Z=[X(:,1),Y(:,1)];

p(k)=anova1(Z);

%D=save(p) unecessary

%X(:,1)=[];Y(:,1)=[]; don't change X or Y!

end

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 4 Comments

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/75236-how-do-i-save-looped-output-into-1-variable-matrix#comment_148159

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/75236-how-do-i-save-looped-output-into-1-variable-matrix#comment_148159

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/75236-how-do-i-save-looped-output-into-1-variable-matrix#comment_148337

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/75236-how-do-i-save-looped-output-into-1-variable-matrix#comment_148337

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/75236-how-do-i-save-looped-output-into-1-variable-matrix#comment_148338

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/75236-how-do-i-save-looped-output-into-1-variable-matrix#comment_148338

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/75236-how-do-i-save-looped-output-into-1-variable-matrix#comment_148340

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/75236-how-do-i-save-looped-output-into-1-variable-matrix#comment_148340

Sign in to comment.