how do i save looped output into 1 variable matrix

6 ビュー (過去 30 日間)
john borsellino
john borsellino 2013 年 5 月 9 日
c=19;
>> D=[];
>> for k=1:c;
Z=[X(:,1),Y(:,1)];
p=anova1(Z)
D=save(p)
X(:,1)=[];Y(:,1)=[];
end
  4 件のコメント
john borsellino
john borsellino 2013 年 5 月 10 日
this window is not working with me
john borsellino
john borsellino 2013 年 5 月 10 日
"save" to store the result of an applied function...in 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

サインインしてコメントする。

採用された回答

James Kristoff
James Kristoff 2013 年 5 月 13 日
% 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
  2 件のコメント
john borsellino
john borsellino 2013 年 5 月 14 日
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..
john borsellino
john borsellino 2013 年 5 月 16 日
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?

サインインしてコメントする。

その他の回答 (1 件)

bym
bym 2013 年 5 月 9 日
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
  2 件のコメント
john borsellino
john borsellino 2013 年 5 月 10 日
but if i don't remove the cloumns from X and Y won't i just get the same answer 19 times...how do i tell matlab to move to the next set of elements in A and B???
john borsellino
john borsellino 2013 年 5 月 10 日
...and thanks for your input and time...only 8 weeks on matlab...be gentle

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by