MATLAB Answers


how do i save looped output into 1 variable matrix

>> D=[];
>> for k=1:c;


Show 1 older comment
Ok then, So… I have (2) 3 x19 matrices, A and B I want to perform anova1 on the first 3 elements of A and the first 3 elements in B Then I need to save individual results into a 3rd matrix that aligns with A and B(if possible) This is what I have so far…
G= 19 % loop count For k= 1:g C=[A(:,1),B(:,1)] % combines 1st column from A with 1st column from B P=anova1(C) % performs anova on “C” and displays answer A(:,1)=[], B(:,1)=[] % removes 1st column from A and B and moves next column into loop end
I think I need to pre-allocate an empty matrix(1x19) to hold the answers as a group and in order, but I can’t find it in the manuals…thanks for your input and time…i have 8 weeks in gentle
this window is not working with me
"save" to store the result of an applied this case i get 19 individual results...(that need to be stored or saved together as a group) "1 individual matrix"== all 19 answers saved together in a new "vertex" or a 1x19 matrix...sorry still learning the jargon

Sign in to comment.


2 Answers

Answer by James Kristoff on 13 May 2013
 Accepted Answer

% 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
% this will store the resulting value in the k-th position in the vector
% *p*


this works...thankyou...can you tell why matlab seperates my identifier column and row of column headers from the data...and how to put them back together...with a new column of data...i have G= [A,B,Z] %%which puts the data columns and the answer column together..
the anova1() function displays a table and chart, along with the p-value,the manual says that i can turn this display off,but it doesn't say how... can you rewrite the p(k)= anova1(Z)....i've tried p(k)= anova1(Z, ,'off'),...=anova1(Z,'off')...idk what to do...what am i not getting?

Sign in to comment.

Answer by bym
on 9 May 2013

% D=[];
p = zeros(c,1); % preallocate
for k=1:c;
%D=save(p) unecessary
%X(:,1)=[];Y(:,1)=[]; don't change X or Y!


but if i don't remove the cloumns from X and Y won't i just get the same answer 19 do i tell matlab to move to the next set of elements in A and B???
...and thanks for your input and time...only 8 weeks on gentle

Sign in to comment.